Home > Backend Development > PHP Tutorial > 关于list()函数有点不懂

关于list()函数有点不懂

WBOY
Release: 2016-06-06 20:17:35
Original
1270 people have browsed it

这个结果为什么是aabaca呢? 为什么只输出了前三个呢 后面的就不管了吗?

<code>$array = array('aa','ba','ca','da','ea','fa');
list($a,$b,$c) =$array;
echo $a,$b,$c; </code>
Copy after login
Copy after login

第二个为什么都打印出来了?和上面的有什么不一样的呢?

<code>$a = list($a,$b,$c) =$array;
print_r($a);
输出结果Array
(
[0] => aa
[1] => ba
[2] => ca
[3] => da
[4] => ea
[5] => fa
)</code>
Copy after login
Copy after login

回复内容:

这个结果为什么是aabaca呢? 为什么只输出了前三个呢 后面的就不管了吗?

<code>$array = array('aa','ba','ca','da','ea','fa');
list($a,$b,$c) =$array;
echo $a,$b,$c; </code>
Copy after login
Copy after login

第二个为什么都打印出来了?和上面的有什么不一样的呢?

<code>$a = list($a,$b,$c) =$array;
print_r($a);
输出结果Array
(
[0] => aa
[1] => ba
[2] => ca
[3] => da
[4] => ea
[5] => fa
)</code>
Copy after login
Copy after login

参考 http://php.net/manual/zh/function.list.php

list函数实现的功能类似于JS中的表达式解构,不用循环取数组的值赋值给变量

$a = list($a,$b,$c) =$array;
等价于下面两行代码
list($a,$b,$c) =$array;
$a = $array;

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