Calculate a sum in a string

前端 未结 5 889
我寻月下人不归
我寻月下人不归 2020-12-20 05:05

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 =          


        
5条回答
  •  無奈伤痛
    2020-12-20 05:32

    I once made a calculator script.

    • It parses the calculation and puts each number and operator on a stack, in reverse polish notation.
    • It calculates the results by executing operations all operations on the stack.

提交回复
热议问题