note 54730 deleted from function.eval by sniper

From: Date: Thu, 29 Dec 2005 09:15:01 +0000
Subject: note 54730 deleted from function.eval by sniper
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-100902@lists.php.net to get a copy of this message
Note Submitter: zend_certified_engineer ---- 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);");

« previous php.notes (#100902) next »