is_numeric();
<?php
$tests = array(
"42",
1337,
"1e4",
"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
'1e4' is numeric
'not numeric' is NOT numeric
'Array' is NOT numeric
'9.1' is numeric
strtotime($time)
$time = '2015adsasd';
var_dump(strtotime($time));
$time1 = '2015-01-11';
var_dump(strtotime($time1));
结果
bool(false)
int()