EchoFool Posted April 27, 2010 Share Posted April 27, 2010 Hey I have 3 variables that have the following info: $Value = 100; $Symbol = '+'; $StartValue = 10; Now i want to put them together to add them together so i did this: $EndValue = $StartValue $Symbol $Value; Which would show as 10 + 100; but that gives an error how do i join them to make it execute as a mathematical thing? Quote Link to comment https://forums.phpfreaks.com/topic/199863-executing-3-variables/ Share on other sites More sharing options...
trq Posted April 27, 2010 Share Posted April 27, 2010 eval. Quote Link to comment https://forums.phpfreaks.com/topic/199863-executing-3-variables/#findComment-1049059 Share on other sites More sharing options...
EchoFool Posted April 27, 2010 Author Share Posted April 27, 2010 I tried that but i get white screen - do the variables have to be comma seperated or something currently i just did : $EndValue = eval($StartValue $Symbol $Value); Quote Link to comment https://forums.phpfreaks.com/topic/199863-executing-3-variables/#findComment-1049060 Share on other sites More sharing options...
PFMaBiSmAd Posted April 27, 2010 Share Posted April 27, 2010 You are going to need to actually read the documentation for the eval() function. It expects valid php code and the only way that it returns a value that you can assign to a variable is if you use a return statement in the php code being evaluated - <?php $Value = 100; $Symbol = '+'; $StartValue = 10; $EndValue = eval("return $StartValue $Symbol $Value;"); echo $EndValue; ?> Quote Link to comment https://forums.phpfreaks.com/topic/199863-executing-3-variables/#findComment-1049066 Share on other sites More sharing options...
EchoFool Posted April 27, 2010 Author Share Posted April 27, 2010 I tried that whilst awaiting a reply and failed i then tried without the "" and also structued with brackets around the variables like return() but still same white screen issue with the error: PHP Parse error: syntax error, unexpected T_RETURN on line 19 On all methods i tried Quote Link to comment https://forums.phpfreaks.com/topic/199863-executing-3-variables/#findComment-1049069 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.