This article describes the usage of list() function in PHP with examples. 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.
list() function definition is 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.
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.