list和each的有关问题
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......一直找下去。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Fresh details of Apple's HomePod-like device with an integrated screen have surfaced and they paint a clearer picture of the device which has been referred to as 'HomeAccessory'. When it launches, it will be Apple's answer to Google's Nest Hub Max an

Update: Saunders Tech has uploaded a tutorial to his YouTube channel (video embedded below) explaining how to install Fortnite and the Epic Games Store on an iPad outside the EU. However, not only does the process require specific beta versions of iO

Apple has officially announced the iPhone 16 and iPhone 16 Plus, introducing key hardware updates with the new A18 chip. Both models come in two sizes—6.1 inches and 6.7 inches—with Super Retina XDR displays. They also feature aluminum designs and ar

Apple has finally lifted the covers off its new high-end iPhone models. The iPhone 16 Pro and iPhone 16 Pro Max now come with larger screens compared to their last-gen counterparts (6.3-in on the Pro, 6.9-in on Pro Max). They get an enhanced Apple A1

Apple's next-generation iPhones are right around the corner. While the company has not shared the date of a new launch event yet, all signs appear to point to a September release, just like last year's iPhone 15 series. Incidentally, footage of dummy

The launches of Apple's next iPhones are not expected for at least another month. Nonetheless, footage showing dummy iPhone 16 units in what are said to be official launch colours continues to emerge online. Incidentally, while Google previously rele

An unpatchable Yubico two-factor authentication key vulnerability has broken the security of most Yubikey 5, Security Key, and YubiHSM 2FA devices. The Feitian A22 JavaCard and other devices using Infineon SLB96xx series TPMs are also vulnerable.All

In addition to the generative AI features plannedfor iOS 18, several Reddit users have discovered that the iOS 18.1 beta enables Adaptive Lighting by default for Nanoleaf’s Matter-compatible smart bulbs. Adaptive Lightning, a staple of Apple Home sin
