Home >Backend Development >PHP Tutorial >PHP assigns values to a set of variables in one step_PHP tutorial
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" }