1//is_numeric — Finds whether a variable is a number or a numeric string
2is_numeric ( $variable ); // returns true or false
1$a = 5; //returns true
2$a = "5"; //returns false
3$a = 5.3; //returns false
4is_int($a);
1// to check the input integer validation we can use is_int() function
2Syntax:
3is_int(parameter);
4
5$x = 10; //returns true
6$x = "123"; //returns false
7$x = 12.365; //returns false
8$x = "ankur"; //returns false
9is_int($x);
1// Check if variable is int
2$id = "1";
3
4if(!intval($id)){
5 throw new Exception("Not Int", 404);
6}
7else{
8 // this variable is int
9}