Re: PHP Newbie can't evaluate numerical string as number [message #175926 is a reply to message #175925] |
Tue, 08 November 2011 09:57 |
Denis McMahon
Messages: 634 Registered: September 2010
Karma:
|
Senior Member |
|
|
On Tue, 08 Nov 2011 09:35:02 +0000, Graham wrote:
> Yes it works! (although I admit I'm not entirely sure why). Many thanks!
> And apologies to Denis for having doubted him.
Heads up - we don't top post in newsgroups. Reply goes at the bottom so
that reading naturally down the page response is after the comment it
applies to.
If you read the php manual for eval http://uk.php.net/manual/en/
function.eval.php , all is explained:
There are two ways to get a value from eval into the script that calls
eval:
a) use return inside the eval code, and assign the value of eval to a
variable, viz:
$evalResult = eval("return $big_number - $small_number;");
echo $evalResult;
b) assign the result to a variable inside the eval code:
eval("$evalResult = $big_number - $small_number;");
echo $evalResult;
These are the two methods I attempted to show in my example.
Rgds
Denis McMahon
|
|
|