获取变量类型

利用gettype()函数来获取变量是哪种类型;

利用is_int()来判断变量里的值是否为int,当然还有is_string,is_bool等。

 1 <?php
 2 $a_bool = TRUE;
 3 $a_str ="foo";
 4 $a_str2 = "foo2";
 5 $an_int = 12;
 6 
 7 echo gettype($a_bool);
 8 echo "<br />";
 9 echo gettype($a_str);
10 echo "<br />";
11 
12 if(is_int($an_int)){
13     $an_int += 4;
14 }
15 
16 if(is_int($an_int)){
17     echo "String:$an_int";
18 }
19 ?>

 

posted @ 2016-04-27 09:49  wong。  阅读(285)  评论(0编辑  收藏  举报