PHP检查变量是否为整数 [英] PHP check if variable is a whole number

查看:126
本文介绍了PHP检查变量是否为整数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个PHP代码:

  $ entityElementCount =( - ($ highScore- $ totalKeywordCount))/ 0.29; 

我想知道的是,如何检查 $ entityElementCount 是否一个整数(2,6,...)或部分(2.33,6.2,...)。



谢谢!

解决方案

  $ entityElementCount =( - ($ highScore- $ totalKeywordCount))/ 0.29; 
if(ctype_digit($ entityElementCount)){
//(ctype_digit((string)$ entityElementCount))//按建议。
printwhole number\\\
;
} else {
printnot whole number\\\
;
}


I have this PHP code:

$entityElementCount = (-($highScore-$totalKeywordCount))/0.29;

What i want to know is, how to check whether $entityElementCount is a whole number (2, 6, ...) or partial (2.33, 6.2, ...).

Thank you!

解决方案

$entityElementCount = (-($highScore-$totalKeywordCount))/0.29;
if (ctype_digit($entityElementCount) ){
    // (ctype_digit((string)$entityElementCount))  // as advised.
    print "whole number\n";
}else{
    print "not whole number\n";
}

这篇关于PHP检查变量是否为整数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆