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.