Home > Backend Development > PHP Tutorial > list和each的有关问题

list和each的有关问题

WBOY
Release: 2016-06-13 13:32:47
Original
1054 people have browsed it

list和each的问题
$fruit = array('a' => 'apple', 'b' => 'banana', 'c' => 'cranberry');

reset($fruit);
while (list($key, $val) = each($fruit)) {
  echo "$key => $val\n";
}
?>
结果:
a => apple
b => banana
c => cranberry

我想问一下,第一次each()的时候,print_r($fruit)的结果应该是:
Array ( [1] => apple [value] => apple [0] => a [key] => a )
这个时候list($key,$val),我们可以看到这个数组是四个参数,而list本身是2个参数,而且顺序怎么会刚好是a赋给$key,apple赋给$val呢?

------解决方案--------------------
list只吃数字索引。
------解决方案--------------------
对。你理解对了。这是list的机制。从0,1......一直找下去。

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