In order to pass an array in the code of create_function(), passing it to the parameter works,
$array = array('a', 'b', 'c');
$func = create_function('$arr', '
foreach($arr as $var) echo "$var<br />";
');
$func($array);
But I’d like to embed an array in the code directly like the eval() capability. Like this,
$array = array('a', 'b', 'c');
eval( 'foreach($array as $var) echo "$var<br />";');
However, this doesn’t work.
$array = array('a', 'b', 'c');
$func = create_function('', '
foreach(' . $array . ' as $var) echo "$var<br />";
');
$func();
So how do I do it? Thanks for your info.
In case you insist on create_function instead of lambda functions
You need a (valid) string representation of the array for the php parser. var_export provides that.
But Berry Langerak’s answer is the way to go.