PHP check if variable is a whole number

后端 未结 20 1238
感动是毒
感动是毒 2020-12-29 20:05

I have this PHP code:

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

What i want to know is, how to check whether $

20条回答
  •  余生分开走
    2020-12-29 20:37

    If you know that it will be numeric (meaning it won't ever be a an integer cast as a string, like "ten" or "100", you can just use is_int():

    $entityElementCount = (-($highScore-$totalKeywordCount))/0.29;
    $entityWholeNumber = is_int($entityElementCount);
    
    echo ($entityWholeNumber) ? "Whole Number!" : "Not a whole number!";
    

提交回复
热议问题