extract
Import variables from array to current symbol table
extract()
function imports variables from an array to the current symbol table.
This function uses the array key name as the variable name and the array key value as the variable value. For each element in the array, a corresponding variable will be created in the current symbol table.
The second parameter type is used to specify how the extract()
function treats such conflicts when a variable already exists and there is an element of the same name in the array.
This function returns the number of variables successfully imported into the symbol table.
Assign key values "Cat", "Dog" and "Horse" to variables $a, $b, and $c:
<?php $a = "Original" ; $my_array = array ( "a" => "Cat" , "b" => "Dog" , "c" => "Horse" ) ; extract ( $my_array ) ; echo "\$a = $a ; \$b = $b ; \$c = $c " ; ?>
Try it yourself
Use all parameters:
<?php $a = "Original" ; $my_array = array ( "a" => "Cat" , "b" => "Dog" , "c" => "Horse" ) ; extract ( $my_array , EXTR_PREFIX_SAME , "dup" ) ; echo "\$a = $a ; \$b = $b ; \$c = $c ; \$dup_a = $dup_a " ; ?>
Try it yourself