Home  >  Article  >  Backend Development  >  Detailed explanation of php list usage

Detailed explanation of php list usage

藏色散人
藏色散人Original
2020-09-12 09:33:153427browse

In PHP, list is a function used to assign values ​​to a set of variables in one operation. This function is only used for numerically indexed arrays. Its syntax is "list(var1,var2...)", The parameter "var1" represents the first variable that needs to be assigned a value.

Detailed explanation of php list usage

Recommended: "PHP Video Tutorial"

list() function is used to give a group of items in one operation Variable assignment.

Note: This function is only used for numerically indexed arrays, and it is assumed that the numerical index starts from 0.

Syntax

list(var1,var2...)

Parameters

var1 Required. The first variable to be assigned a value.

var2,... Optional. More variables need to be assigned values.

Description

list() function assigns values ​​to a set of variables using elements in the array.

Note that, similar to array(), list() is actually a language construct, not a function.

Example

Assign the values ​​in the array to some variables:

<?php
$my_array = array("Dog","Cat","Horse");
list($a, $b, $c) = $my_array;
echo "I have several animals, a $a, a $b and a $c.";
?>

Running result:

I have several animals, a Dog, a Cat and a Horse.

The above is the detailed content of Detailed explanation of php list usage. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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