Jump to content

executing 3 variables


EchoFool

Recommended Posts

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?

Link to comment
https://forums.phpfreaks.com/topic/199863-executing-3-variables/
Share on other sites

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;
?>

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 :(

 

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.