note 54730 added to function.eval
| From: | zend_certified_engineer at osu1 dot php dot net | Date: | Wed, 13 Jul 2005 21:58:25 +0000 |
| Subject: | note 54730 added to function.eval | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-91923@lists.php.net to get a copy of this message | ||
I wanted to use an array in my eval statement, but ended up with a parse error. I came up with this
solution ... if someone faced this problem but had a better way of fixing it I would be glad to hear
it.
function array_to_str($array, $name)
/*
will create an array definition so it can be used in eval function.
note that name does not need the $ at calltime
*/
{
foreach($array as $k => $v)
{
$got_var .= "\${$name}[\"$k\"] = '$v';\n";
}
return $got_var;
}
$str=array_to_str($var, "my_ar");
eval("$str; print_r(\$my_ar);");
----
Manual Page -- http://www.php.net/manual/en/function.eval.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+54730
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+54730&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+54730&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+54730&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+54730&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+54730&report=yes&reason=non-english
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+54730&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+54730&report=yes
Search -- http://master.php.net/manage/user-notes.php