Home >php教程 >php手册 >php用一步操作给一组变量进行赋值

php用一步操作给一组变量进行赋值

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-06-13 10:42:521256browse

list() 用一步操作给一组变量进行赋值。 list() 仅能用于数字索引的数组并假定数字索引从 0 开始。

例如

$result = mssql_query("SELECT User, Sex, Age FROM _User",$conn);
list($user, $sex, $age) = mssql_fetch_row($result);
echo $user.
;
echo $sex.
;
echo $age;

也可以为数组赋值:

$hotcity = array(jinan, qingdao, zibo);
list($addr[0], $addr[1], $addr[2]) = $hotcity ;
var_dump($addr);
?>

输出:
array(3) { [2]=> string(4) "淄博" [1]=> string(7) "青岛" [0]=> string(5) "济南" }

 

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn