Re: [PHP] extract() question
I needed this once, but I could not figure out how to just create the vars in current scope. If my_extract() is called from within a function, then the variables will not be available unless you declare them global (which kinda makes the function pointless). Any ideas? -Jason Garber IonZoft.com At 06:55 PM 11/18/2001 -0500, Joe Stump wrote: >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 <[EMAIL PROTECTED]> > >"How would this sentence be different if pi equaled 3?" -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] extract() question
You may want to do something like this instead: --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 <[EMAIL PROTECTED]> "How would this sentence be different if pi equaled 3?" msg40414/pgp0.pgp Description: PGP signature
[PHP] extract() question
There is this array which I would like to convert into a series variables using the extract function: "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