Jump to content

Calculating expression from variable


Joonake

Recommended Posts

Hello all, I have a problem when I am trying to create calculator with PHP. I have created form that you can use to add numbers and operations to input field, but I just cant figure out how to "calculate" the calculation that is stored in variable.

 

For example:

$expression = "5";
$expression .= "+";
$expression .= "5";

$answer = $expression;

 

This way I get just the "5+5" on $answer, but I would like to get "10". I dont want to write my own function to parse the calculation because I know that it exists, just dont know how this is done. I have tried to use printf but it wont help.

 

Anyone can help me?

Link to comment
https://forums.phpfreaks.com/topic/207938-calculating-expression-from-variable/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.