This example describes the use of the list () function in PHP. Share to everyone for your reference, specific 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 an array of numeric indices, and assume that the numeric index starts at 0 .
The list () function is defined as follows:
List (Var1,var2 ...)
parameter Description :
Var1 required. The first variable to assign a value to.
Var2,... Optional. More variables that need to be assigned values.
The sample code is as follows:
<?php
//$arr =array (' name ' => ' Tom ', ' pwd ' => ' 123456 ');//Wrong! Index must be a numeric index!
//$arr =array (' 1 ' => ' Tom ', ' 2 ' => ' 123456 ');//Wrong! Digital index must start from 0!
$arr =array (' Tom ', ' 123456 ');
List ($name, $pwd) = $arr;
echo "Welcome". $name. "! Remember your password: ". $pwd;
? >
I hope this article will help you with the PHP program design.