技术库 技术手册 字体库 知识点 词汇表 联系我们
内容搜索   
本站最新推出网站制作字体库。
当前位置:WEB技术知识资源库(www.cn-web.com) .: PHP技术 .: 基础教程 .: php中的list()函数

php中的list()函数


list — 把数组中的值赋给一些变量

说明

void list ( mixed $varname, mixed $... )
list() 用一步操作给一组变量进行赋值
例子1:
<?php

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

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

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

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

?>
 
例子2:
<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>
 
 

Google
 

对此文章打分评级

用户评论

增加评论
此文章还没有任何评论!
网站地图 - 知识词汇 - 全文检索 - 广告服务 - 帮助中心 - 联系我们
.:www.cn-web.com
网站技术开发联盟之WEB开发技术知识库
联系人:老韩(QQ:5679551)
晋ICP备07003487号