This article mainly introduces the usage of the list () function in PHP, and analyzes the functions, parameter definitions, usage skills, and related precautions of the list () function in combination with the instance form, for more information about the list () function in PHP, see the example in this article. We will share this with you for your reference. The details are as follows:
The list () function in PHP is used to assign values to a group of variables in an operation.
Note:: The array variable can only be an array of numeric indexes, and it is assumed that the numeric index starts from 0.
List () function definitionAs follows:
List (var1, var2 ...)
Parameter description:
Var1 is required. The first variable to be assigned a value.
Var2,... optional. More variables to be assigned values.
Sample codeAs follows:
<? Php // $ arr = array ('name' => 'Tom ', 'pwd' => '123'); // error! The index must be a Digital Index! // $ Arr = array ('1' => 'Tom ', '2' => '123'); // error! The number index must start from 0! $ Arr = array ('Tom ', '123'); list ($ name, $ pwd) = $ arr; echo "Welcome". $ name ."! Remember your password: ". $ pwd;?>
I hope this article will help you with PHP programming.