php extract

The extract() function automatically creates local variables from an array. The indices of the array elements become the variable names:

$person = array(‘name’ => “Fred”, ‘age’ => 35, ‘wife’ => “Betty”);

extract($person);

// $name, $age, and $wife are now set

extract Example in php

<?php
$a = "Original";
$my_array = array("a" => "Cat","b" => "Dog", "c" => "Horse");
extract($my_array);
echo "\$a = $a; \$b = $b; \$c = $c";
?>
<?php

/* Suppose that $var_array is an array returned from
   wddx_deserialize */

$size = "large";
$var_array = array("color" => "blue",
                   "size"  => "medium",
                   "shape" => "sphere");
extract($var_array, EXTR_PREFIX_SAME, "wddx");

echo "$color, $size, $shape, $wddx_size\n";

?>

Leave a Comment