Sophie

Sophie

distrib > Mandriva > 2008.1 > x86_64 > by-pkgid > ebb1914cf182a88528b4547490db1dd8 > files > 632

kdewebdev-quanta-doc-3.5.9-2mdv2008.1.x86_64.rpm

<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
>&#13;     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
>&#13;     <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
>&#13;	 If there is a collision, overwrite the existing variable.
	</P
></DD
><DT
>EXTR_SKIP</DT
><DD
><P
>&#13;	 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
>&#13;	 Prefix all variables with <TT
CLASS="parameter"
><I
>prefix</I
></TT
>.
	</P
></DD
></DL
>
    </P
><P
>&#13;     If <TT
CLASS="parameter"
><I
>extract_type</I
></TT
> is not specified, it is
     assumed to be EXTR_OVERWRITE.
    </P
><P
>&#13;     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
>&#13;     <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
>&#13;     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
>&#13;     <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&nbsp;
  2&nbsp;&#60;php?
  3&nbsp;
  4&nbsp;/* Suppose that $var_array is an array returned from
  5&nbsp;   wddx_deserialize */
  6&nbsp;
  7&nbsp;$size = "large";
  8&nbsp;$var_array = array ("color" =&#62; "blue",
  9&nbsp;                    "size"  =&#62; "medium",
 10&nbsp;                    "shape" =&#62; "sphere");
 11&nbsp;extract ($var_array, EXTR_PREFIX_SAME, "wddx");
 12&nbsp;
 13&nbsp;print "$color, $size, $shape, $wddx_size\n";
 14&nbsp;
 15&nbsp;?&#62;
 16&nbsp;      </PRE
></TD
></TR
></TABLE
></DIV
></TD
></TR
></TABLE
>
    </P
><P
>&#13;     The above example will produce:
     <TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><PRE
CLASS="programlisting"
>  1&nbsp;
  2&nbsp;blue, large, sphere, medium
  3&nbsp;     </PRE
></TD
></TR
></TABLE
>
    </P
><P
>&#13;     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
>