0

echo $equation = "(5+10)-8+2*2";

echo $equation //outputs (5+10)-8+2*2

I want to show this result 11

  • Uuse `eval` on the string and the result would be the mathematical result. – IT goldman Jul 02 '22 at 17:33
  • Please read: [How do I format my posts using Markdown or HTML?](https://stackoverflow.com/help/formatting) because `echo $equation = "(5+10)-8+2*2";` will not even assign a value to `$equation`.... – Luuk Jul 02 '22 at 17:36
  • Does this answer your question? [calculate math expression from a string using eval](https://stackoverflow.com/questions/18880772/calculate-math-expression-from-a-string-using-eval) – nice_dev Jul 02 '22 at 18:22
  • Please provide enough code so others can better understand or reproduce the problem. – ethry Jul 02 '22 at 21:04

1 Answers1

0

use this :

echo eval($equation);
Ali SSN
  • 357
  • 3
  • 6