Reffer this link.
I know operand with string type translate to number, and then usual math
But see these sample codes:
echo intval(1e1); // 10
var_dump("1e1" == 10); // true, and it's ok
echo intval(0x1A); // 26
var_dump("0x1A" == 26); // true, and it's ok
echo intval(042); // 34
var_dump("042" == 34); // fasle, Why ?!!!
Why last code return false.
That’s because string-to-number conversion in PHP is based on some ancient C function –
strtod. And its rules are as follows:As you see, ‘1e1’ string has non-empty sequence ‘1’ followed by a decimal exponent ‘e1’. So, it will be converted into a decimal number – and becomes 10.
‘0x1A’ string follows the rules for hexadecimal number, and will be converted into 26 accordingly. But as there’s no specific rule for octadecimal number, ‘042’ will be converted into a plain decimal – and becomes 42. Which is, of course, not equal to 34.
This should not be confused with how number literals are parsed by PHP itself. A number literal that starts with 0 is considered representing an octadecimal. So,
intval(042)is essentially the same asintval(34)– but not the same asintval("042").