PHP list函数

PHP list函数教程

PHP 中的 list 函数用于把 数组 中的值赋给一些变量。该函数只用于数字索引的数组。

list函数详解

语法

list(var1,var2...);

参数

参数 描述
var1 需要赋值的变量。
var2 需要赋值的变量。

返回值

返回被赋值的数组。

案例

list数组赋值给变量

使用 list() 函数,将数组赋值给变量

<?php echo "嗨客网(www.haicoder.net)<br>"; $arr = array("haicoder", "www.haicoder.net", 109, 1024); list($a, , $c, $d) = $arr; echo "a = ", $a, "<br>"; echo "c = ", $c, "<br>"; echo "d = ", $d, "<br>";

程序运行后,控制台输出如下:

27_PHP list函数详解.png

我们使用了 list 函数,实现了返回数组中的值赋值给了变量。

PHP list函数总结

PHP 中的 list 函数用于把数组中的值赋给一些变量。该函数只用于数字索引的数组。