Home  >  Article  >  Backend Development  >  PHP assigns values ​​to a set of variables in one step_PHP tutorial

PHP assigns values ​​to a set of variables in one step_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 17:44:23942browse

list() assigns values ​​to a set of variables in one step. list() can only be used with numerically indexed arrays and assumes that numerical indexing starts at 0.

For example

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

You can also assign values ​​to arrays:

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

Output:
array(3) { [2]=> string(4) "Zibo" [1]=> string(7) "Qingdao" [0]=> string(5) " Jinan" }

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/478757.htmlTechArticlelist() Use one step to assign values ​​to a set of variables. list() can only be used with numerically indexed arrays and assumes that numerical indexing starts at 0. For example $result = mssql_query("SELECT User, Sex, Ag...
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