3 ms·
"For instance, 123 == “123foo” evaluates to true (see what it’s doing there?), but 0123 == “0123foo” is false (hmm)." Can anyone explain this to me? I know if
by Superfrag 6y ago
"For instance, 123 == “123foo” evaluates to true (see what it’s doing there?), but 0123 == “0123foo” is false (hmm)."
Can anyone explain this to me? I know if a string starts with the number, PHP takes the number part and throws the rest, so "0123foo" should be 0123 for the comparison, so why is that false?
- tsm 6y agoEdit: I was wrong. 0123 is octal, not decimal [Incorrect original post: 0123 evaluates to the integer value 123]
- deleted 6y ago[deleted]
- mam2 6y agoSo ?
- bugfix 6y ago0123 (octal) != 123 (int)
- civilized 6y agoBut the integer part of the string "0123foo" is also 123
- munk-a 6y agoNot quite - 0123 is the octal value 123 which happens to be 83 in decimal. Numbers starting with a 0 in PHP are assumed to be in octal but I this isn't the case for strings[1] - to add to confusion "123foo" == 123 => true but "0123foo" = 0123 => false. 1. https://3v4l.org/hAoL2 https://3v4l.org/hAoL2
- deleted 6y ago[deleted]