Reputation: 310
Well. I'm having a problem with the eval(); function in PHP. I don't quite understand how to store the returned data into a variable to print.. my code is as follows:
<?php
$a = 4;
$write = eval("$a+$a;");
echo $write;
?>
I'm not sure what I'm doing wrong. When I run the PHP script, all it does is output nothing.. Any help is appreciated
Upvotes: 0
Views: 331
Reputation: 7211
<?php
$a = 4;
eval("\$write = \$a+\$a;");
var_dump($write);
?>
It will return int(8)
Upvotes: 0
Reputation: 119827
try eval("\$write = \$a+\$a;")
http://php.net/manual/en/function.eval.php
Upvotes: 0
Reputation: 54719
From the PHP documentation:
eval() returns
NULL
unless return is called in the evaluated code, in which case the value passed to return is returned.
Upvotes: 4