Sophie

Sophie

distrib > Mandriva > 9.1 > ppc > media > main > by-pkgid > 0afeee9cca140e167a996902b9a677c5 > files > 1325

php-manual-en-4.3.0-2mdk.noarch.rpm

<HTML
><HEAD
><TITLE
>list</TITLE
><META
NAME="GENERATOR"
CONTENT="Modular DocBook HTML Stylesheet Version 1.7"><LINK
REL="HOME"
TITLE="PHP Manual"
HREF="index.html"><LINK
REL="UP"
TITLE="Array Functions"
HREF="ref.array.html"><LINK
REL="PREVIOUS"
TITLE="ksort"
HREF="function.ksort.html"><LINK
REL="NEXT"
TITLE="natcasesort"
HREF="function.natcasesort.html"><META
HTTP-EQUIV="Content-type"
CONTENT="text/html; charset=ISO-8859-1"></HEAD
><BODY
CLASS="refentry"
BGCOLOR="#FFFFFF"
TEXT="#000000"
LINK="#0000FF"
VLINK="#840084"
ALINK="#0000FF"
><DIV
CLASS="NAVHEADER"
><TABLE
SUMMARY="Header navigation 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.ksort.html"
ACCESSKEY="P"
>Prev</A
></TD
><TD
WIDTH="80%"
ALIGN="center"
VALIGN="bottom"
></TD
><TD
WIDTH="10%"
ALIGN="right"
VALIGN="bottom"
><A
HREF="function.natcasesort.html"
ACCESSKEY="N"
>Next</A
></TD
></TR
></TABLE
><HR
ALIGN="LEFT"
WIDTH="100%"></DIV
><H1
><A
NAME="function.list"
></A
>list</H1
><DIV
CLASS="refnamediv"
><A
NAME="AEN8920"
></A
><P
>    (PHP 3, PHP 4 )</P
>list&nbsp;--&nbsp;
     Assign variables as if they were an array
    </DIV
><DIV
CLASS="refsect1"
><A
NAME="AEN8923"
></A
><H2
>Description</H2
>void <B
CLASS="methodname"
>list</B
> ( mixed ...)<BR
></BR
><P
>&#13;     Like <A
HREF="function.array.html"
><B
CLASS="function"
>array()</B
></A
>, this is not really a function,
     but a language construct.  <B
CLASS="function"
>list()</B
> is used to
     assign a list of variables in one operation.
    </P
><DIV
CLASS="note"
><BLOCKQUOTE
CLASS="note"
><P
><B
>Note: </B
>
      <B
CLASS="function"
>list()</B
> only works on numerical arrays and assumes 
      the numerical indices start at 0.
     </P
></BLOCKQUOTE
></DIV
><P
>&#13;     <TABLE
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
CLASS="EXAMPLE"
><TR
><TD
><DIV
CLASS="example"
><A
NAME="AEN8938"
></A
><P
><B
>Example 1. <B
CLASS="function"
>list()</B
> examples</B
></P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
CELLPADDING="5"
><TR
><TD
><PRE
CLASS="php"
>&#60;?php

$info = array('coffee', 'brown', 'caffeine');

// Listing all the variables
list($drink, $color, $power) = $info;
print "$drink is $color and $power makes it special.\n";

// Listing some of them
list($drink, , $power) = $info;
print "$drink has $power.\n";

// Or let's skip to only the third one
list( , , $power) = $info;
print "I need $power!\n";

?&#62;</PRE
></TD
></TR
></TABLE
></DIV
></TD
></TR
></TABLE
>
    </P
><P
>&#13;     <TABLE
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
CLASS="EXAMPLE"
><TR
><TD
><DIV
CLASS="example"
><A
NAME="AEN8943"
></A
><P
><B
>Example 2. An example use of <B
CLASS="function"
>list()</B
></B
></P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
CELLPADDING="5"
><TR
><TD
><PRE
CLASS="php"
>&#60;table&#62;
 &#60;tr&#62;
  &#60;th&#62;Employee name&#60;/th&#62;
  &#60;th&#62;Salary&#60;/th&#62;
 &#60;/tr&#62;

&#60;?php

$result = mysql_query ("SELECT id, name, salary FROM employees",$conn);
while (list ($id, $name, $salary) = mysql_fetch_row ($result)) {
    print (" &#60;tr&#62;\n".
           "  &#60;td&#62;&#60;a href=\"info.php?id=$id\"&#62;$name&#60;/a&#62;&#60;/td&#62;\n".
           "  &#60;td&#62;$salary&#60;/td&#62;\n".
           " &#60;/tr&#62;\n");
}

?&#62;

&#60;/table&#62;</PRE
></TD
></TR
></TABLE
></DIV
></TD
></TR
></TABLE
>
    </P
><DIV
CLASS="warning"
><P
></P
><TABLE
CLASS="warning"
BORDER="1"
WIDTH="100%"
><TR
><TD
ALIGN="CENTER"
><B
>Warning</B
></TD
></TR
><TR
><TD
ALIGN="LEFT"
><P
>&#13;     <B
CLASS="function"
>list()</B
> assigns the values starting with the right-most
     parameter. If you are using plain variables, you don't have to worry
     about this. But if you are using arrays with indices you usually expect
     the order of the indices in the array the same you wrote in the
     <B
CLASS="function"
>list()</B
> from left to right; which it isn't. It's
     assigned in the reverse order.
    </P
></TD
></TR
></TABLE
></DIV
><P
>&#13;     <TABLE
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
CLASS="EXAMPLE"
><TR
><TD
><DIV
CLASS="example"
><A
NAME="AEN8952"
></A
><P
><B
>Example 3. Using <B
CLASS="function"
>list()</B
> with array indices</B
></P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
CELLPADDING="5"
><TR
><TD
><PRE
CLASS="php"
>&#60;?php

$info = array('coffee', 'brown', 'caffeine');

list($a[0], $a[1], $a[2]) = $info;

var_dump($a);

?&#62;</PRE
></TD
></TR
></TABLE
></DIV
></TD
></TR
></TABLE
>
     Gives the following output (note the order of the elements compared in
     which order they were written in the <B
CLASS="function"
>list()</B
> syntax):
     <TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
CELLPADDING="5"
><TR
><TD
><PRE
CLASS="screen"
>array(3) {
  [2]=&#62;
  string(8) "caffeine"
  [1]=&#62;
  string(5) "brown"
  [0]=&#62;
  string(6) "coffee"
}</PRE
></TD
></TR
></TABLE
>
    </P
><P
>&#13;     See also <A
HREF="function.each.html"
><B
CLASS="function"
>each()</B
></A
>, <A
HREF="function.array.html"
><B
CLASS="function"
>array()</B
></A
> 
     and <A
HREF="function.extract.html"
><B
CLASS="function"
>extract()</B
></A
>.
    </P
></DIV
><DIV
CLASS="NAVFOOTER"
><HR
ALIGN="LEFT"
WIDTH="100%"><TABLE
SUMMARY="Footer navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
><A
HREF="function.ksort.html"
ACCESSKEY="P"
>Prev</A
></TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="index.html"
ACCESSKEY="H"
>Home</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
><A
HREF="function.natcasesort.html"
ACCESSKEY="N"
>Next</A
></TD
></TR
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
>ksort</TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="ref.array.html"
ACCESSKEY="U"
>Up</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
>natcasesort</TD
></TR
></TABLE
></DIV
></BODY
></HTML
>