Re: extract() question

From: Date: Sun, 18 Nov 2001 23:55:30 +0000
Subject: Re: extract() question
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-75051@lists.php.net to get a copy of this message
You may want to do something like this instead: <? function my_extract($arr) { if(is_array($arr) && sizeof($arr)) { while(list($key,$val) = each($arr) { $new_var = str_replace(' ','_',$key); global $$new_var; $$new_var = $val; } } } ?> --Joe On Sun, Nov 18, 2001 at 04:21:46PM -0500, David Bernier wrote: > There is this array which I would like to convert into a series variables using the extract > function: > > <? > $oz = array( > "lion" => "courage", > "dorothy" => "kansas", > "scarecrow" => "brain" > "tin man" => "heart"); > > extract($oz); > ?> > > now, I would like to access my new variables. it is obviously easy for $lion, $dorothy, and > $scarecrow but it isn't for "tin man". > > from this, I have 3 or 4 questions: > 1) has $oz["tin man"] been passed into a variable? > 2) if yes, how do I access the variable that came out of $oz["tin man"]? > 3) let's pretend that I have no control over the names of the keys for $oz, how should I > have called extract() to tell it to replace the space between "tin" and "man" by > a underscore character? > 4) finally, is there a way to access and retrieve that values of the symbol table without > knowing their names? > > David > Joe Stump <joe@joestump.net> ------------------------------------------------------------------------ "How would this sentence be different if pi equaled 3?"

« previous php.general (#75051) next »