extract()
Take the array values out of the array (”extract” them). Use extract() to create new variables into the current scope from the key/value pair of an array.
By default it will overwrite any conflicting variables but you can set the way that is handled through use of the second parameter. See the manual entry for your options.
This works similarly to how the old register globals worked on the superglobals, only here you say which array gets extracted. As you might guess, extracting $_GET or $_POST for example opens up some security issues. This is not recommended.
Note: The original array is left unchanged. Using EXTR_REFS however will extract the variables by reference which could result in altering the original array values.
Some examples:
$arr = array ('a'=>'apple', 'b'=>'banana', 'c'=>'cucumber', 'd'=>array( 'tall'=>'monkey', 'short'=>'spider', 'thin'=>'worm' ), 17=>'seventeen' ); extract($arr); /* We now have $a holding the value of 'apple', $b contains 'banana', $c contains 'cucumber', and $d is an array of 'tall','short', and 'thin' as shown above $17 is not a valid variable name so it is not created */ $arr2 = array( 'test'=>'nothing', 'b'=>'boat', 'another'=>'something' ); extract($arr2, EXTR_IF_EXISTS); /* Due to EXTR_IF_EXISTS as the second parameter, only $b is extracted - replacing the existing value so now $b contains 'boat' Since $test and $another do not already exist, they are ignored */ $arr3 = array( 'a'=>'qwerty', 17=>'asdf' ); extract($arr3, EXTR_PREFIX_ALL, 'kb'); /* The variables created here are: $kb_a containing 'qwerty' $kb_17 containing 'asdf' $a still contains the value 'apple' */
