Clevercode found a way to return multiple values by receiving a PHP function. Python used to be a regular use, and PHP has this method.
<?phpfunction Retinfo () { $name = ' Zhang San '; $age =; $sex = 1; Return Array ($name, $age, $sex);} List ($name 1, $age 1, $sex 1) = Retinfo (); echo "name:${name1},age:${age1},sex:${sex1}\r\n"; list ($name 2, $age 2, $sex 2) = Array (' John Doe ', 19,2); echo "name:${name2},age:${age2},sex:${sex2}\r\n";? >
List ()
The PHP list () assigns the values in the array to some variables in one step. Like array (), list () is not a real function, but a language structure.
Grammar:
void list (mixed var, mixed ...) Note: List () can only be used for arrays of numeric indexes and assumes that the numeric index starts at 0.
Example 1:
<?php$arr_age = Array ($wang, $li, $zhang) = $arr _age;echo $wang; Output: 18echo $zhang; Output:25?>
Example 2, data table query:
$result = mysql_query ("SELECT ID, username, email from user", $conn) and while (list ($id, $username, $email) = Mysql_fetch_row ( $result) { echo "user name: $username <br/>"; echo "e-mail: $email";}
List () using array index
The list () allows the use of another array to receive values from the array, except that when using an indexed array, the order of assignment is the opposite of the order listed in list ():
$arr _age = Array ($a [0], $a [1], $a [2]) = $arr _age;print_r ($a);
The output $a array structure is as follows:
Array ([2] = [1] = [0] = 18)