Home > Article > Backend Development > How to determine whether a variable is an integer in php
Two methods for php to determine whether a variable is an integer
1. If you are sure that your variable is a number , PHP has a built-in judgment function: is_int detects whether the variable is an integer;
2. But sometimes the variables we receive are numbers or numerical strings (such as form input, they are usually strings), In this way, we cannot use the daois_int() function to simply determine whether it is an integer. We need to use the is_numeric() and strpos() functions to determine whether it is an integer:
(1) Use the is_numeric() function to determine whether it is an integer. It is a number or a string of numbers;
(2) Use strpos() to determine whether the number contains a decimal point;
if(!属is_numeric($age)||strpos($age,".")!==false){ echo "不是整数"; }else{ echo "是整数"; }
Recommended tutorial: "PHP Tutorial"
The above is the detailed content of How to determine whether a variable is an integer in php. For more information, please follow other related articles on the PHP Chinese website!