<HTML ><HEAD ><TITLE >extract</TITLE ><META NAME="GENERATOR" CONTENT="Modular DocBook HTML Stylesheet Version 1.44"><LINK REL="HOME" TITLE="PHP Manual" HREF="manual.html"><LINK REL="UP" TITLE="Array functions" HREF="ref.array.html"><LINK REL="PREVIOUS" TITLE="end" HREF="function.end.html"><LINK REL="NEXT" TITLE="in_array" HREF="function.in-array.html"></HEAD ><BODY BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#840084" ALINK="#0000FF" ><DIV CLASS="NAVHEADER" ><TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TH COLSPAN="3" ALIGN="center" >PHP Manual</TH ></TR ><TR ><TD WIDTH="10%" ALIGN="left" VALIGN="bottom" ><A HREF="function.end.html" >Prev</A ></TD ><TD WIDTH="80%" ALIGN="center" VALIGN="bottom" ></TD ><TD WIDTH="10%" ALIGN="right" VALIGN="bottom" ><A HREF="function.in-array.html" >Next</A ></TD ></TR ></TABLE ><HR ALIGN="LEFT" WIDTH="100%"></DIV ><H1 ><A NAME="function.extract" >extract</A ></H1 ><DIV CLASS="refnamediv" ><A NAME="AEN4095" ></A >extract -- Import variables into the symbol table from an array </DIV ><DIV CLASS="refsect1" ><A NAME="AEN4098" ></A ><H2 >Description</H2 ><DIV CLASS="funcsynopsis" ><P ></P ><CODE CLASS="FUNCDEF" >void extract</CODE >(array var_array, int [<SPAN CLASS="optional" >extract_type</SPAN >] , string [<SPAN CLASS="optional" >prefix</SPAN >] );<P ></P ></DIV ><P > This function is used to import variables from an array into the current symbol table. It takes associative array <TT CLASS="parameter" ><I >var_array</I ></TT > 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 <TT CLASS="parameter" ><I >extract_type</I ></TT > and <TT CLASS="parameter" ><I >prefix</I ></TT > parameters. </P ><P > <B CLASS="function" >extract()</B > checks for colissions with existing variables. The way collisions are treated is determined by <TT CLASS="parameter" ><I >extract_type</I ></TT >. It can be one of the following values: <P ></P ><DL ><DT >EXTR_OVERWRITE</DT ><DD ><P > If there is a collision, overwrite the existing variable. </P ></DD ><DT >EXTR_SKIP</DT ><DD ><P > If there is a collision, don't overwrite the existing variable. </P ></DD ><DT >EXTR_PREFIX_SAME</DT ><DD ><P >If there is a collision, prefix the new variable with <TT CLASS="parameter" ><I >prefix</I ></TT >. </P ></DD ><DT >EXTR_PREFIX_ALL</DT ><DD ><P > Prefix all variables with <TT CLASS="parameter" ><I >prefix</I ></TT >. </P ></DD ></DL > </P ><P > If <TT CLASS="parameter" ><I >extract_type</I ></TT > is not specified, it is assumed to be EXTR_OVERWRITE. </P ><P > Note that <TT CLASS="parameter" ><I >prefix</I ></TT > is only required if <TT CLASS="parameter" ><I >extract_type</I ></TT > is EXTR_PREFIX_SAME or EXTR_PREFIX_ALL. </P ><P > <B CLASS="function" >extract()</B > checks each key to see if it constitues a valid variable name, and if it does only then does it proceed to import it. </P ><P > A possible use for extract is to import into symbol table variables contained in an associative array returned by <A HREF="function.wddx-deserialize.html" ><B CLASS="function" >wddx_deserialize()</B ></A >. </P ><P > <TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><P ><B >Example 1. <B CLASS="function" >Extract()</B > example</B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" WIDTH="100%" ><TR ><TD ><PRE CLASS="programlisting" > 1 2 <php? 3 4 /* Suppose that $var_array is an array returned from 5 wddx_deserialize */ 6 7 $size = "large"; 8 $var_array = array ("color" => "blue", 9 "size" => "medium", 10 "shape" => "sphere"); 11 extract ($var_array, EXTR_PREFIX_SAME, "wddx"); 12 13 print "$color, $size, $shape, $wddx_size\n"; 14 15 ?> 16 </PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > </P ><P > The above example will produce: <TABLE BORDER="0" BGCOLOR="#E0E0E0" WIDTH="100%" ><TR ><TD ><PRE CLASS="programlisting" > 1 2 blue, large, sphere, medium 3 </PRE ></TD ></TR ></TABLE > </P ><P > 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. </P ></DIV ><DIV CLASS="NAVFOOTER" ><HR ALIGN="LEFT" WIDTH="100%"><TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" ><A HREF="function.end.html" >Prev</A ></TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="manual.html" >Home</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" ><A HREF="function.in-array.html" >Next</A ></TD ></TR ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" >end</TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="ref.array.html" >Up</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" >in_array</TD ></TR ></TABLE ></DIV ></BODY ></HTML >