<?php
$valoresStr = '500038;204932
500038;204932
100398;204932
100398;204932
100398;204932
100398;204932';
foreach ($arrayValores as $valor => $soma) {
$valoresStr = str_replace($valor, $soma . ';' . $valor, $valoresStr); }
echo PHP_EOL;
echo $valoresStr;
PD9waHAKJHZhbG9yZXNTdHIgPSAnNTAwMDM4OzIwNDkzMgo1MDAwMzg7MjA0OTMyCjEwMDM5ODsyMDQ5MzIKMTAwMzk4OzIwNDkzMgoxMDAzOTg7MjA0OTMyCjEwMDM5ODsyMDQ5MzInOwoKJGFycmF5VGVtcCA9IGV4cGxvZGUoY2hyKDEwKSwgdHJpbSgkdmFsb3Jlc1N0cikpOwoKJGFycmF5VmFsb3JlcyA9IGFycmF5X2NvdW50X3ZhbHVlcygkYXJyYXlUZW1wKTsKCnZhcl9kdW1wKCRhcnJheVZhbG9yZXMpOwoKZm9yZWFjaCAoJGFycmF5VmFsb3JlcyBhcyAkdmFsb3IgPT4gJHNvbWEpIHsKICAgICR2YWxvcmVzU3RyID0gc3RyX3JlcGxhY2UoJHZhbG9yLCAkc29tYSAuICc7JyAuICR2YWxvciwgJHZhbG9yZXNTdHIpOwp9CgplY2hvIFBIUF9FT0w7CgplY2hvICR2YWxvcmVzU3RyOwo=