您的位置:首页 > 编程语言 > PHP开发

判断PHP数据类型

2016-01-29 23:45 531 查看
常用方式:is_int(), is_float()l, is_numeric(), is_array()...

另一种更快捷的方式:用 === 或 !== ,即全等和不全等运算符来判断。

I've found a faster way of determining an array. If you use is_array() millions of times, you will notice a *huge* difference. On my machine, this method takes about 1/4 the time of using is_array().
Cast the value to an array, then check (using ===) if it is identical to the original.
<?php
if ( (array) $unknown !== $unknown ) {
echo '$unknown is not an array';
} else {
echo '$unknown is an array';
}
?>
http://php.net/manual/zh/function.is-array.php
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: