


PHP list() A simple instance of assigning the values in the array to a variable, list array
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:
<?php $arr_age = array(18, 20, 25); list($wang, $li, $zhang) = $arr_age; echo $wang; //输出:18 echo $zhang; //输出:25 ?>
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"; }
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.

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SublimeText3 English version
Recommended: Win version, supports code prompts!

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

SublimeText3 Linux new version
SublimeText3 Linux latest version

Dreamweaver CS6
Visual web development tools