Home >Backend Development >PHP Tutorial >How to use list function
PHP list() function is used to assign values to a set of variables in one operation.
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.','.$b.'和'.$c.'是php中文网的三位老师。'; ?>
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!