Home > php教程 > php手册 > body text

PHP 判断变量类型实现代码_php基础

WBOY
Release: 2016-05-17 09:02:16
Original
1447 people have browsed it

PHP 包括几个函数可以判断变量的类型,例如:gettype(),is_array(),is_float(),is_int(),is_object() 和 is_string()。

复制代码 代码如下:

$s = "this is a string";
$i = 9;
$arr = array(2,4,6);
is_string($s); //返回TRUE,表示$s是一个字符串变量
is_string($i); //返回FALSE,表示$i不是一个字符串变量
is_array($arr); //返回TRUE,表示$arr是一个数组
is_array($s); //返回FALSE,表示$s不是一个数组
$str = "this is a string";
$int = 9;
$bool = FALSE;
echo "\$str的类型是:".gettype($str);
echo "
";
echo "
";
echo "\$int的类型是:".gettype($int);
echo "
";
echo "
";
echo "\$bool的类型是:".gettype($bool);
?>
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!