list
来源: http://php.net/list
<?php
$info = array(‘coffee‘, ‘brown‘, ‘caffeine‘);
列出所有变量
list($drink, $color, $power) = $info;
echo "$drink is $color and $power makes it special.\n";
// 列出他们的其中一个
list($drink, , $power) = $info;
echo "$drink has $power.\n";
// 或者让我们跳到仅第三个
list( , , $power) = $info;
echo "I need $power!\n";
// list() 不能对字符串起作用
list($bar) = "abcde";
var_dump($bar); // NULL
?>
<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)) {
echo " <tr>\n" .
" <td><a href=\"info.php?id=$id\">$name</a></td>\n" .
" <td>$salary</td>\n" .
" </tr>\n";
}
?>
</table>
<?php
list($a, list($b, $c)) = array(1, array(2, 3));
var_dump($a, $b, $c);
// int(1)
// int(2)
// int(3)
?>
<?php
$info = array(‘coffee‘, ‘brown‘, ‘caffeine‘);
list($a[0], $a[1], $a[2]) = $info;
var_dump($a);
?>