★ wanayoo — archive 1999 http://www.php.net/manual/de/function.extract.phpNouvelle recherche | Portail wanayoo

PHP Home Page

Manual Table of Contents
Up to Arrays
Quick Reference
English version of this pageJapanese version of this pageItalian version of this pageFrench version of this pageHungarian version of this page
Arrays
* array
* array_count_values
* array_flip
* array_keys
* array_merge
* array_merge_recursive
* array_multisort
* array_pad
* array_pop
* array_push
* array_rand
* array_reverse
* array_shift
* array_slice
* array_splice
* array_unshift
* array_values
* array_walk
* arsort
* asort
* compact
* count
* current
* each
* end
* extract
* in_array
* key
* krsort
* ksort
* list
* next
* pos
* prev
* range
* reset
* rsort
* shuffle
* sizeof
* sort
* uasort
* uksort
* usort
Manual: extract
View the source code for this pageSearch the site



Previous page
 end
 Updated
Sat, 12 Aug 2000
in_array 
Next page


extract

(PHP3 >= 3.0.7, PHP4 )

extract --  Import variables into the symbol table from an array

Description

void extract (array var_array [, int extract_type [, string prefix]])

This function is used to import variables from an array into the current symbol table. It takes associative array var_array and treats keys as variable names and values as variable values. For each key/value pair it will create a variable in the current symbol table, subject to extract_type and prefix parameters.

extract() checks for colissions with existing variables. The way collisions are treated is determined by extract_type. It can be one of the following values:

EXTR_OVERWRITE

If there is a collision, overwrite the existing variable.

EXTR_SKIP

If there is a collision, don't overwrite the existing variable.

EXTR_PREFIX_SAME

If there is a collision, prefix the new variable with prefix.

EXTR_PREFIX_ALL

Prefix all variables with prefix.

If extract_type is not specified, it is assumed to be EXTR_OVERWRITE.

Note that prefix is only required if extract_type is EXTR_PREFIX_SAME or EXTR_PREFIX_ALL.

extract() checks each key to see if it constitues a valid variable name, and if it does only then does it proceed to import it.

A possible use for extract is to import into symbol table variables contained in an associative array returned by wddx_deserialize().

Beispiel 1. extract example


<?

/* 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");

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

?>
      

The above example will produce:

blue, large, sphere, medium
	 

The $size wasn't overwritten, becaus we specified EXTR_PREFIX_SAME, which resulted in $wddx_size being created. If EXTR_SKIP was specified, then $wddx_size wouldn't even have been created. EXTR_OVERWRITE would have cause $size to have value "medium", and EXTR_PREFIX_ALL would result in new variables being named $wddx_color, $wddx_size, and $wddx_shape.


User Contributed Notes: extract


alexphpdoc@blamey.freeserve.co.uk
13-Apr-2000 11:23
When the prefix is used an underscore ('_') is inserted, i.e.
<PRE>
extract(array("var" => "val"), EXTR_PREFIX_ALL, "pre");
</PRE>
will create a variable called $pre_var NOT $prevar.
(This is with PHP 4.0b3pl1)



ricky@ea1.com
17-Jul-2000 10:49
FYI: The opposite of this function is compact().


buck@goldendome.com
24-Jul-2000 10:04
arrrgh! after banging my head for a couple days I looked at the source and in php3 (not sure re:php4) it specifically _does_not_ import the numerically indexed values...so just sending a plain array doesn't import any variables.


 About Notes


Previous page
 end
 Updated
Sat, 12 Aug 2000
in_array 
Next page





Who's responsible for this?
Top of this page

Site
Hosting:



Located in
United States
Elements of this website are subject to copyright.
Questions about installing or using PHP should be directed to one of the mailing lists.
Only questions about the website should be directed to webmaster@php.net.