hi2all
i want to search for first number after comma and if match found replace second number with another number i specify it
my code is
$value='1 0 0,4 2 0,1 20 0,3 0 0,2 0 0,2 0 0,3 0 0,4 0 0,4 0 0,3 0 0,3 0 0,4 0 0,4 0 0,1 0 0,4 0 0,2 0 0,1 0 0,2 0 0,0 0 0,0 0 0,0 0 0,0 0 0,0 0 0,0 0 0,10 20 0,15 20 0,0 0 0,0 0 0,11 20 0,23 10 0,0 0 0,0 0 0,27 7 0,0 0 0,0 0 0,0 0 0,0 0 0,0 0 0,16 1 0,0 0 0';
$resouces_array=explode(',', $value);
foreach ($resouces_array as $key=> $value) {
$first_number =substr($value,0,2);
$second_number = explode(' ', $value);
if($first_number == 23){
$second_number[1]= 50;
}
$string_valo= implode(' ' ,$second_number);
$after_spli=str_pad($string_valo, 6,',');
echo $after_spli;
}
i want the output to be like that
$value='1 0 0,4 2 0,1 20 0,3 0 0,2 0 0,2 0 0,3 0 0,4 0 0,4 0 0,3 0 0,3 0 0,4 0 0,4 0 0,1 0 0,4 0 0,2 0 0,1 0 0,2 0 0,0 0 0,0 0 0,0 0 0,0 0 0,0 0 0,0 0 0,10 20 0,15 20 0,0 0 0,0 0 0,11 20 0,23 50 0,0 0 0,0 0 0,27 7 0,0 0 0,0 0 0,0 0 0,0 0 0,0 0 0,16 1 0,0 0 0';
but my code produce that
1 0 0,4 2 0,1 20 03 0 0,2 0 0,2 0 0,3 0 0,4 0 0,4 0 0,3 0 0,3 0 0,4 0 0,4 0 0,1 0 0,4 0 0,2 0 0,1 0 0,2 0 0,0 0 0,0 0 0,0 0 0,0 0 0,0 0 0,0 0 0,10 20 015 20 00 0 0,0 0 0,11 20 023 50 00 0 0,0 0 0,27 7 00 0 0,0 0 0,0 0 0,0 0 0,0 0 0,16 1 00 0 0,
so what is wrong and is there any simple solution other mine ??