Home >Backend Development >PHP Tutorial >How to use list function

How to use list function

藏色散人
藏色散人Original
2019-02-12 10:39:404115browse

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

How to use list function

php list() function Syntax

Function: Used to assign values ​​to a set of variables in one operation.

Syntax:

list(var1,var2...)

Parameters:

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

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

Note: Use elements in an array to assign values ​​to a set of variables. list() is actually a language structure, not a function.

php list() function example 1

<?php
$my_array = array("西门","灭绝","无忌");
list($a, , $c) = $my_array;
echo "php中文网有 $a 和 $c 两位老师。";
?>

Output:

php中文网有 西门 和 无忌 两位老师。

php list() function example 2

<?php
$my_array = array("西门","灭绝","无忌");
list($a,$b,$c) = $my_array;
echo $a.&#39;,&#39;.$b.&#39;和&#39;.$c.&#39;是php中文网的三位老师。&#39;;
?>

Output:

西门,灭绝和无忌是php中文网的三位老师。

This article is an introduction to the PHP list function. I hope it will be helpful to friends in need!

The above is the detailed content of How to use list function. 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
Previous article:How to use reset functionNext article:How to use reset function