教程集 www.jiaochengji.com
教程集 >  脚本编程  >  php  >  正文 PHP使用list函数需要注意什么

PHP使用list函数需要注意什么

发布时间:2020-12-05   编辑:jiaochengji.com
教程集为您提供PHP使用list函数需要注意什么等资源,欢迎您收藏本站,我们将为您提供最新的PHP使用list函数需要注意什么资源

在PHP中,list() 函数用于在一次操作中给一组变量赋值。

示例:

<?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.";
?>

输出:

I have several animals, a Dog, a Cat and a Horse.

在使用list() 函数时,需要注意:

● list() 实际上是一种语言结构,不是函数。

● list() 函数只用于数字索引的数组中

我们可以看看上面例子中my_array数组:

<?php
$my_array = array("Dog","Cat","Horse");
var_dump($my_array);
?>

输出:

array (size=3)
  0 => string 'Dog' (length=3)
  1 => string 'Cat' (length=3)
  2 => string 'Horse' (length=5)

可以看出my_array数组的索引就是数字索引。

● 假定数字索引从 0 开始,即从索引0开始为变量赋值

如果对应的数字索引不存在,则对应位的变量就为空值。

以上就是PHP使用list函数需要注意什么的详细内容,更多请关注教程集其它相关文章!

  • 本文原创发布教程集,转载请注明出处,感谢您的尊重!
  • 您可能感兴趣的文章:
    PHP使用list函数需要注意什么
    map在python中什么意思
    python中的tuple是什么
    python中extend是什么意思
    python里pop是什么意思
    python中sort是什么意思
    python3怎么调用map函数
    php中function是什么意思
    PHP list(),each(),reset()函数应用详解
    php list函数如何使用

    [关闭]
    ~ ~