【发布时间】:2017-01-20 03:50:24
【问题描述】:
我在 PHP 文档中遇到了这个示例:
<?php
$tests = array(
"42",
1337,
0x539,
02471,
0b10100111001,
1337e0,
"not numeric",
array(),
9.1
);
foreach ($tests as $element) {
if (is_numeric($element)) {
echo "'{$element}' is numeric", PHP_EOL;
} else {
echo "'{$element}' is NOT numeric", PHP_EOL;
}
}
?>
输出:
'42' is numeric
'1337' is numeric
'1337' is numeric
'1337' is numeric
'1337' is numeric
'1337' is numeric
'not numeric' is NOT numeric
'Array' is NOT numeric
'9.1' is numeric
“42”之后的五个示例都计算为“1337”。我可以理解为什么'1337e0'(科学记数法)会出现这种情况,但我不明白为什么其他人会出现这种情况。
我在文档的 cmets 中找不到任何人提到它,我也没有在这里找到它,所以任何人都可以解释为什么“0x539”、“02471”和“0b10100111001”都评估为“ 1337'。
【问题讨论】:
标签: php evaluation isnumeric