Вопрос об интервью: В php, 123 == 0123?

" Top, Право, Нижняя часть, Покинутая"
реклама R eally
B
Limerick

22
задан meagar 30 April 2010 в 14:49
поделиться

5 ответов

Prefixing a number with 0 indicates octal (base 8), much the same way 0x indicates hex (base 16).

24
ответ дан 29 November 2019 в 03:20
поделиться

This code:

var_dump(123);
var_dump(0123);

will get you:

int 123
int 83

This is because 0123 is octal notation (because of the 0 at the beginning), while 123 is decimal.


For more information, you can take a look at the Integer section of the manual.


An even trickier question would have been to ask about 79 and 079, for instance :

var_dump(79);
var_dump(079);

will get you :

int 79
int 7

(9 is not a valid digit in octal ;-) )

69
ответ дан 29 November 2019 в 03:20
поделиться

1) When we use == operator in php, it checks if values are equal. So 5=="5" => true 2) When we use === operator in php, it checks if values and data types are equal. So 5==="5" => false

123==0123 => false ALSO 123 === 0123 => false

123 is decimal number : 123 0123 is an octal number (as it starts with 0) : 83

123 is not equal to 83

5
ответ дан 29 November 2019 в 03:20
поделиться

Because 0123 means "123 in octal (base 8)", which is 83 in decimal.

2
ответ дан 29 November 2019 в 03:20
поделиться

0123 is notation for an octal number (83 decimal, off the top of my head), whilst 123 is a decimal number. Therefore, they are not equal.

2
ответ дан 29 November 2019 в 03:20
поделиться
Другие вопросы по тегам:

Похожие вопросы: