php array behaving strangely with key value 07 & 08

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

This is mostly used when specifying unix permissions:

chmod("myfile", 0660);

Except for that it’s rarely something that you’d want to do.

This is described in the PHP Manual.

Leave a Comment