$arr = eval(\"array(\'foo\'=>\'bar\');\"); // returns null var_dump($arr);
Can someone please explain why did I get null instead of an array?>
You need to return the array.
return
From the docs:
eval() returns NULL unless return is called in the evaluated code, in which case the value passed to return is returned.
eval()
NULL
So you need to do:
$arr = eval("return array('foo'=>'bar');");