这是PHP中的错误吗? [英] Is this a bug in PHP?

查看:59
本文介绍了这是PHP中的错误吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:
php数组的键值07&奇怪. 08

Possible Duplicate:
php array behaving strangely with key value 07 & 08

我在PHP中发现了一些奇怪的东西,如果我使用数字数组,第8个数组将被忽略,在这里,当我将'Cherry'放入$ fruit [08]中时,PHP接缝会跳过它.

I've found something weird in PHP, if I use numeric arrays the 8th array gets ignored, here when I put 'Cherry' into $fruit[08], php seams to step over it.

这是怎么回事?这是错误还是其他?

What's going on ? Is this a bug or something else.

<pre>
<?php

$fruit[01] = "Apples";
$fruit[02] = "Pears";
$fruit[03] = "Bananas";
$fruit[04] = "Grape";
$fruit[05] = "Orange";
$fruit[06] = "Peach";
$fruit[07] = "Lemon";
$fruit[08] = "Cherry";
$fruit[09] = "Mango";

print_r($fruit);

?>
</pre>

输出:

Array
(
    [1] => Apples
    [2] => Pears
    [3] => Bananas
    [4] => Grape
    [5] => Orange
    [6] => Peach
    [7] => Lemon
    [0] => Mango
)

推荐答案

由于前导零,您的索引被视为八进制数字.

Your indices are being treated as octal numbers because of the leading zeroes.

0809都将被评估为零,因此您的最后一个条目(芒果")以数组索引0结尾.

08 and 09 will both be evaluated as zero, so your last entry ("Mango") ends up in array index 0.

这篇关于这是PHP中的错误吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆