Here are the students to introduce two about the PHP judgment variable is a whole number of two methods, I hope this article will help you.
Method One: Can be used four or five into the number, and then compared with the original number, such as floor (3.1) The result should be 3, at this time obviously 3!=3.1, or with ceil () function also line, this can also determine whether it is an integer.
Method two: Using PHP's own function is_int () can easily determine whether the number is an integer.
To illustrate:
$a = 3.3;
Method One
| The code is as follows |
Copy Code |
if (floor ($a) = = $a) { echo "$a is an integer!"; }else{ echo "$a not an integer!"; } |
Method Two,
| The code is as follows |
Copy Code |
if (Is_int ($a)) { echo "$a is an integer!"; }else{ echo "$a not an integer!"; } |
Note:is_int () and floor check the type of the variable, not the contents of the variable, when judging the string, you can use the following to replace:
| The code is as follows |
Copy Code |
function Str_is_int ($STR) { return 0 = = = strcmp ($str, (int) $str); } |
http://www.bkjia.com/PHPjc/632620.html www.bkjia.com true http://www.bkjia.com/PHPjc/632620.html techarticle Here are the students to introduce two about the PHP judgment variable is a whole number of two methods, I hope this article will help you. Method One: You can use four or five into the number, ...