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

Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.