$a = '9223372036854775807'; $b = '9223372036854775808'; if ($a == $b) { echo "$a == $b\n"; } else { echo "$a != $b\n"; } // displays 9223372036854775807 == 9223372036854775808
ããã¥ã¢ã«ãè¦ãã¨
If you compare a number with a string or the comparison involves numerical strings, then each string is converted to a number and the comparison performed numerically.
PHP: Comparison Operators - Manual
æ°å¤ã£ã½ãæåå(numerical string)ãå«ãæ¯è¼ã¯æ°å¤ã«å¤æãã¦ããæ¯è¼ãããã¨ã«ãªã£ã¦ããã
When a string is evaluated in a numeric context, the resulting value and type are determined as follows.
If the string does not contain any of the characters '.', 'e', or 'E' and the numeric value fits into integer type limits (as defined by PHP_INT_MAX), the string will be evaluated as an integer. In all other cases it will be evaluated as a float.
The value is given by the initial portion of the string. If the string starts with valid numeric data, this will be the value used. Otherwise, the value will be 0 (zero). Valid numeric data is an optional sign, followed by one or more digits (optionally containing a decimal point), followed by an optional exponent. The exponent is an 'e' or 'E' followed by one or more digits.
PHP: Strings - Manual
ã§ãæååâæ°å¤å¤æã§ã¯ãPHP_INT_MAXãè¶ ããã¨floatã«ãªãã
ã®ã§ãfloatã«å¤æããã¦åãå¤ã«ãªããã¨ãããã¨ãããããæååã¨ãã¦æ¯è¼ãããå ´åã¯"==="æ¼ç®åã使ããªããã°ãªããªãã
ããã«ãæ°å¤ã£ã½ãæåå(Zend/zend_operators.hã®is_numeric_string)ã¯16é²æ°ãææ°è¡¨è¨ã使ããã®ã§
$ php -r 'var_dump("0xFF" == "255");' bool(true) $ php -r 'var_dump("1e2" == "100");' bool(true)
ã¨ããããã«ãªãã