Extracting Values from Arrays with extract() : extract « Data Structure « PHP






Extracting Values from Arrays with extract()

 
<?php 

$customer = array('first' => 'R', 'last' => 'W', 'age' => 24, ); 

extract($customer); 
print "<p>$first $last is $age years old.</p>"; 

extract($customer, EXTR_PREFIX_ALL, 'cust'); 
print "<p>$cust_first $cust_last is $cust_age years old.</p>"; 
?>
  
  








Related examples in the same category

1.Add the prefix pts to each array key and then make each variable that results into a reference.
2.extract( ) function converts elements into variables
3.extract($points, EXTR_REFS|EXTR_PREFIX_ALL, 'pts');
4.extract($scores, EXTR_PREFIX_ALL, 'score');
5.Using extract on an associative array
6.Using extract with the EXTR_PREFIX_ALL directive
7.Using EXTR_PREFIX_ALL on a numeric array