How to use list function

藏色散人
Release: 2023-04-05 07:20:02
Original
4096 people have browsed it

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...)
Copy after login

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 两位老师。";
?>
Copy after login

Output:

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

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;;
?>
Copy after login

Output:

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

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!

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