I have the following code:
$fut1 = 9814; $Awaarde = 8304; $Bwaarde = 5111; $arrayAantallen = array("A", "B"); foreach ($arrayAantallen as $letter) { $lijstMijnWaardes .= 'number_format(((round(' . ${$letter."waarde"} . ', -2))/1000), 1) + '; } $waarde = $lijstMijnWaardes + number_format(((round($fut1, -2))/1000), 1);
The result of $waarde is 9.8 (the value of $fut1), but I expect 23.2 (9.8+8.3+5.1).
Any idea? Thank you in advance!
edit: when I echo $lijstMijnWaardes, that result seems te be correct:
number_format(((round(8304, -2))/1000), 1) + number_format(((round(5111, -2))/1000), 1) +
Advertisement
Answer
Based on the above requirement, Try this,
$fut1 = 9814; $Awaarde = 8304; $Bwaarde = 5111; $arrayAantallen = array("A", "B"); foreach ($arrayAantallen as $letter) { $lijstMijnWaardes += number_format(((round(${$letter."waarde"}, -2))/1000), 1); } $waarde = $lijstMijnWaardes + number_format(((round($fut1, -2))/1000), 1);
Problem with your Code:
in the line $lijstMijnWaardes .= 'number_format(((round(' . ${$letter."waarde"} . ', -2))/1000), 1) + ';
you are concatenating strings not forming an equation.
Advice:
Instead of forming the complete equation try performing that equation in every step.