如何显示任何包含整数值的变量 is_int()?
我有这样的代码:
$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”。这有什么问题吗?
I have this code:
$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";
I am fetching the value from MySql as "cad_count integer(5)", then I check whether this value is an integer or not and show the "Value not Integer" accordingly. What's wrong in it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用
is_numeric()
或ctype_digit()
。这些函数测试给定变量是否是数字的有效表示或仅包含数字。is_int
测试变量的类型是否为int
,以及 mysql_fetch * 函数将整数作为字符串返回。Use
is_numeric()
orctype_digit()
. These functions test if the given variable is a valid representation of a number or contains only digits.is_int
tests if the variable's type isint
, and mysql_fetch* functions return integers as strings.is_numeric()
更适合您。为了使 is_int() 工作,你必须从旧的值中获取 int 值is_numeric()
is better for you. To make is_int() work, you have to make int value from old one