How do I calculate this string with php?

WHAT?

New member
I don't write a lot of PHP for some syntax might be off, but I would look up the preg_split() function, below is an example that may work. It splits the numbers string into parts separated by the + sign.

$number = "1+2+3";
$numbers = preg_split("+",$number);

$sum = 0;

for($i = 0; $i < $numbers; $i++){
.....$sum += (int)$numbers;
}

$sum whould now equal 6
 
I have a variable e.g. $number="1+2+3" but I want to change the variable to $number=6 or "6" by doing the math inside the string
I have a variable e.g. $number="(1+2)*3" but I want to change the variable to $number=9 or "9" by doing the math inside the string
 
Back
Top