PHP list() A simple example of assigning values ​​in an array to variables, list array_PHP tutorial

WBOY
Release: 2016-07-12 08:49:39
Original
884 people have browsed it

PHP list() A simple instance of assigning the values ​​in the array to a variable, list array

list()

PHP list() assigns the values ​​in the array to some variables in one step. Like array(), list() is not a true function, but a language construct.

Grammar:

void list( mixed var, mixed ... )Note: list() can only be used on numerically indexed arrays and assumes that numerical indexing starts from 0.

Example 1:

<&#63;php
$arr_age = array(18, 20, 25);
list($wang, $li, $zhang) = $arr_age;
echo $wang;    //输出:18
echo $zhang;    //输出:25
&#63;>
Copy after login

Example 2, data table query:

$result = mysql_query("SELECT id, username, email FROM user",$conn);
while(list($id, $username, $email) = mysql_fetch_row($result)) {
  echo "用户名:$username<br />";
  echo "电子邮箱:$email";
}
Copy after login

list() uses array index

List() allows the use of another array to receive the values ​​assigned to the array, but when using an index array, the order of assignment is reversed from the order listed in list():

$arr_age = array(18, 20, 25);

list($a[0], $a[1], $a[2]) = $arr_age;

print_r($a); The output $a array structure is as follows:

Array ( [2] => 25 [1] => 20 [0] => 18 )

The above simple example of PHP list() assigning the value in the array to a variable is all the content shared by the editor. I hope it can give you a reference, and I hope you will support Bangkejia more.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1136640.htmlTechArticlePHP list() A simple instance of assigning the values ​​in the array to a variable, list array list() PHP list( ) Assign values ​​from an array to some variables in one step. Like array(), list() is not really...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template