PHP list () assigns the values in the array to a simple instance of the variable, list Array

Source: Internet
Author: User

PHP list () assigns the values in the array to a simple instance of the variable, list Array

List ()

PHP list () assigns values in the array to some variables with one-step operations. Like array (), list () is not a real function, but a language structure.

Syntax:

Void list (mixed var, mixed...) Note: list () can only be used as an array of numeric indexes and assume that the numeric index starts from 0.

Example 1:

<? Php $ arr_age = array (18, 20, 25); list ($ wang, $ li, $ zhang) = $ arr_age; echo $ wang; // output: 18 echo $ zhang; // output: 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: $ username <br/>"; echo "email: $ email ";}

List () using array Indexes

In list (), you can use another array to receive values assigned to an array. However, when an indexed array is used, the order of values is the opposite of 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)

In the above PHP list (), the simple example of assigning the values in the array to the variables is all the content shared by the small editor. I hope to give you a reference, and I hope you can support the help house a lot.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.