Extract. Was Re: Feature?

From: Date: Wed, 26 Sep 2001 14:47:57 +0000
Subject: Extract. Was Re: Feature?
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-68874@lists.php.net to get a copy of this message
Just looking up that extract function, the manual says it extracts into the current symbol table. I assume that means that within foo() the array would be extracted into local variables. Is that right? -Steve On Wednesday, September 26, 2001, at 06:50 AM, Alister wrote:
Follow up to my own message: If you want to also skip even needing the empty 'array()' (new fianl example) - check if it is an array, and only do the first extract of the parameters if there's something there. <?php function foo($p='') { $foodefault = array( 'foo_fred'=> '<strong>default fred</strong>', 'foo_banana' => '<strong>default bananananana</strong>', ); if (is_array($p)) extract ($p, EXTR_PREFIX_ALL, 'foo'); // get values extract ($foodefault, EXTR_SKIP, "foo"); // get defaults echo "$foo_fred / $foo_banana"; } echo "Both in place: "; foo(array('fred' => 'hello', 'banana' => 'world')); echo "<br /> Now with a missing param: "; foo(array('fred' => 'hello')); echo "<br /> Now both missing params: "; foo(array()); echo "<br /> and with no array: "; foo(); ?>


« previous php.general (#68874) next »