如何显示任何变量的整数值is_int()?

时间:2011-09-12 15:02:39

标签: php variables return-value isinteger

我有这段代码:

$showCountSql    = "select cad_count from counteraccountdtl WHERE cad_userid =".$_SESSION['UID']." LIMIT 1";
$showCountresult = mysql_query($showCountSql);
$showCountrow    = mysql_fetch_array($showCountresult);
$newCount        = $showCountrow[cad_count];

if(is_int($newCount))
 echo "Value  is Integer";
else
 echo "Value not Integer";

我从MySql获取值为“cad_count integer(5)”,然后检查该值是否为整数,并相应地显示“Value not Integer”。它有什么问题?

2 个答案:

答案 0 :(得分:2)

使用is_numeric()ctype_digit()。这些函数测试给定变量是否为数字的有效表示或仅包含数字。

is_int测试变量的类型是否为int,而mysql_fetch *函数将整数作为字符串返回。

答案 1 :(得分:0)

is_numeric()对你更好。要使is_int()起作用,必须从旧的

中获取int值
$var = intval($var);