list

(unknown)

list --  Assign variables as if they were an array

Description

void list ( mixed ...)

Like array(), this is not really a function, but a language construct. list() is used to assign a list of variables in one operation.

Note: list() only works on numerical arrays and assumes the numerical indices start at 0.

Example 1. list() examples

<?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";

?>

Example 2. An example use of list()

<table>
 <tr>
  <th>Employee name</th>
  <th>Salary</th>
 </tr>

<?php

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

?>

</table>

See also each(), array() and extract().