$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.
From the docs:
eval()returnsNULLunlessreturnis called in the evaluated code, in which case the value passed toreturnis returned.
So you need to do:
$arr = eval("return array('foo'=>'bar');");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With