Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unexpected behaviour in an array with some values

Tags:

php

My code is:

$arr=[02,05,07,08,09];
print_r($arr)

and output is:

Array
(
    [0] => 2
    [1] => 5
    [2] => 7
    [3] => 0
    [4] => 0
)

Why it converts 08 and 09 to 0??

like image 505
Brijesh Singh Avatar asked Jul 11 '16 10:07

Brijesh Singh


1 Answers

Numbers beginning with a zero are considered to be in base 8.

See PHP docs: Integers - Syntax.

To use octal notation, precede the number with a 0 (zero). To use hexadecimal notation precede the number with 0x. To use binary notation precede the number with 0b.

like image 151
ShiraNai7 Avatar answered Sep 21 '22 10:09

ShiraNai7