list
(PHP 3, PHP 4 )list -- 把数组中的值赋给一些变量
说明
void list ( mixed ...)
像 array() 一样,这不是真正的函数,而是语言结构。list() 用一步操作给一组变量进行赋值。 注: list() 仅能用于数字索引的数组并假定数字索引从 0 开始。 例子 1. list() 例子<?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";?>
例子 2. 使用 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>
(PHP 3, PHP 4 )list -- 把数组中的值赋给一些变量
说明
void list ( mixed ...)
像 array() 一样,这不是真正的函数,而是语言结构。list() 用一步操作给一组变量进行赋值。 注: list() 仅能用于数字索引的数组并假定数字索引从 0 开始。 例子 1. list() 例子<?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";?>
例子 2. 使用 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>
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货