note 38083 deleted from function.extract by aidan
| From: | aidan@php.net | Date: | Thu, 09 Sep 2004 09:14:13 +0000 |
| Subject: | note 38083 deleted from function.extract by aidan | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-76289@lists.php.net to get a copy of this message | ||
Note Submitter: dkellner
----
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.