The example in this article describes the usage of the list() function in PHP. Share it with everyone for your reference, the details are as follows:
The list() function in PHP is used to assign values to a set of variables in one operation.
Note: The array variable here can only be a numerically indexed array, and it is assumed that the numerical index starts from 0. The
list() function is defined as follows:
list(var1,var2...)
Parameter description:
var1 Required. The first variable to be assigned a value.
var2,... Optional. More variables need to be assigned values.
The sample code is as follows:
<?php //$arr=array('name'=>'Tom','pwd'=>'123456'); //错误!索引必须为数字索引! //$arr=array('1'=>'Tom','2'=>'123456'); //错误!数字索引必须从0开始! $arr=array('Tom','123456'); list($name,$pwd)=$arr; echo "Welcome ".$name." ! Remember your password:".$pwd; ?>
I hope this article will be helpful to everyone in PHP programming.
The above has introduced a brief analysis of the usage examples of the list function in PHP, including the relevant content. I hope it will be helpful to friends who are interested in PHP tutorials.