I have string like this: $string = "a + b + c";. Now I would like to calculate the string as sum.
For example:
$a = 10;
$b = 10;
$c = 10;
$string = "a + b + c";
echo "Result is ".$string;
output-> Result is 30
$string = "a + b * c";
echo "Result is ".$string;
output-> Result is 110
Thanks in advance
The variables in your string are missing the dollar signs. I wrote and tested a script for you that adds these signs to the variables and then parses the string as PHP code using the function
eval().This will output
30.