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
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.
try eval("\$write = \$a+\$a;")
<?php
$a = 4;
eval("\$write = \$a+\$a;");
var_dump($write);
?>
It will return int(8)
<?php
$a = 4;
$write = eval("return $a+$a;");
echo $write;
?>