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$a = 5; //returns true
2$a = "5"; //returns false
3$a = 5.3; //returns false
4is_int($a);
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}
1<?php
2$strings = array('1820.20', '10002', 'wsl!12');
3foreach ($strings as $testcase) {
4 if (ctype_digit($testcase)) {
5 echo "The string $testcase consists of all digits.\n";
6 } else {
7 echo "The string $testcase does not consist of all digits.\n";
8 }
9}
10?>