note 38083 added to function.extract
| From: | dkellner at rn2 dot php dot net | Date: | Sun, 07 Dec 2003 21:33:04 +0000 |
| Subject: | note 38083 added to function.extract | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-61606@lists.php.net to get a copy of this message | ||
If you are tired of always writing "EXTR_PREFIX_ALL" (which i believe is the most useful
feature of extract) then you can use a function like:
function xtract($a,$prefix) {
foreach($a as $key=>$val) $GLOBALS["${prefix}_${key}"]=$val;
}
and then call it like
xtract($myarray, "my");
This, however, will NOT work when called inside a function. The reason is the array GLOBALS which
we put the extracted variables into. (I couldn't find a way to do the same trick in functions,
also I had problems determining if xtract is called from another function or not.) So be sure to
always use it outside.
----
Manual Page -- http://www.php.net/manual/en/function.extract.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+38083
Delete -- http://master.php.net/manage/user-notes.php?action=delete+38083&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+38083&report=yes
Search -- http://master.php.net/manage/user-notes.php