PHP list () assigns a value in an array to a simple instance of a variable _php instance

Source: Internet
Author: User
Tags mixed

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: The list () can only be used for arrays of numeric indices and assumes that the numeric index starts at 0.

Example 1:

<?php
$arr _age = Array (a);
List ($wang, $li, $zhang) = $arr _age;
echo $wang;    Output:
$zhang echo;    Output:
?>

Example 2, datasheet 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 "e-mail: $email";
}

List () using an array index

The list () allows the use of another array to receive the value of an array assignment, except that when an indexed array is used, the order of assignment 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] => [1] => [0] => 18)

The above PHP list () to assign the value of the array to a simple example of the variable is a small set to share all the content, hope to give you a reference, but also hope that we support the cloud habitat community.

Related Article

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.