PHP数组键值07和放大器举止异常; 08 [英] php array behaving strangely with key value 07 & 08
问题描述
我有个数组
$months[01] = 'January';
$months[02] = 'February';
$months[03] = 'March';
$months[04] = 'April';
$months[05] = 'May';
$months[06] = 'June';
$months[07] = 'July';
$months[08] = 'August';
$months[09] = 'September';
$months[10] = 'October';
$months[11] = 'November';
$months[12] = 'December';
现在阵确实为关键 07
&放大器输出不正确的值; 08
。
Now the array does not output correct value for key 07
& 08
.
试着做的print_r($个月)
你不会得到任何键值月
和零关键指标月
。
Try doing print_r($months)
you will not get any key value August
and zero key index for September
.
虽然我能够通过删除前导零来解决这个问题,我仍然很想知道同样的原因。
Though I’m able to solve the problem by removing the leading zero, still I would love to know the reason for same.
即使是PHP编辑器插播一些问题,但无法分辨是什么问题。
Even the PHP editor spots some problem but unable to tell what is the problem.
感谢
推荐答案
若干前prepending 0意味着PHP解析它作为在prepending 0X导致其解析为同样的方式一个八进制值十六进制值。取出零,它会正常工作。
Prepending 0 before a number means PHP parses it as an octal value in the same way that prepending 0x causes it to be parsed as a hexadecimal value. Remove the zero, and it will work fine.
echo 07; // prints 7
echo 010; // prints 8
指定UNIX权限时,这主要用于:
This is mostly used when specifying unix permissions:
chmod("myfile", 0660);
除了它的很少的东西,你想要做的事。
Except for that it's rarely something that you'd want to do.
这是在 PHP手册描述。
这篇关于PHP数组键值07和放大器举止异常; 08的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!