PHP is_int() function PHP

PHP is_int() function  

PHP is_int() function

PHP is_int() function

By using php is_int function, we can check the input variable is integer or not. This function was introduced in PHP 4.0

Syntax

  1. bool is_int (mixed $var)  

Parameters

Parameter Description Is compulsory
var_name The variable being checked. compulsory

Return type

This function returns true if var_name is an integer, Otherwise false.

Example 1

  1.     $x=123;  
  2.     echo is_int($x);  
  3. ?>  

Output:

PHP Variable Handling is_int() function

Example 2

  1.     $x = 56;   
  2.     $y = "xyz";   
  3.     
  4.     if (is_int($x))   
  5.     {   
  6.         echo "$x is Integer \n" ;   
  7.     }   
  8.     else  
  9.     {   
  10.         echo "$x is not an Integer \n" ;   
  11.     }   
  12.     if (is_int($y))   
  13.     {   
  14.         echo "$y is Integer \n" ;   
  15.     }   
  16.     else  
  17.     {   
  18.         echo "$y is not Integer \n" ;   
  19.     }   
  20. ?>  

Output:

PHP Variable Handling is_int() function

Example 3

  1.     
  2.     $check = 12345;  
  3.     if( is_int($check ))   
  4.     {  
  5.             echo $check . " is an int!";  
  6.     }   
  7.     else   
  8.     {  
  9.             echo $check . " is not an int!";  
  10.     }  
  11.     
  12. ?>   

Output:

PHP Variable Handling is_int() function

Download free E-book of PHP


#askProgrammers
Learn Programming for Free


Join Programmers Community on Telegram


Talk with Experienced Programmers


Just drop a message, we will solve your queries