Home > Backend Development > PHP Problem > How to use php list function

How to use php list function

藏色散人
Release: 2023-02-28 13:42:02
Original
2719 people have browsed it

How to use php list function

How to use the php list 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.";
?>
Copy after login

Output:

I have several animals, a Dog, a Cat and a Horse.
Copy after login

Definition and Usage

list() function is used to assign values ​​to a set of variables in one operation.

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

Recommended: "PHP Tutorial"<br/>

Syntax

list(var1,var2...)
Copy after login

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.

Return value: Returns the assigned array.

Example 1

Using the first and third variables:

<?php
$my_array = array("Dog","Cat","Horse");
list($a, , $c) = $my_array;
echo "我在这里只用了 $a 和 $c 变量。";
?>
Copy after login

Output: <br/>

<br/>
Copy after login

The above is the detailed content of How to use php list function. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
php
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