PHP is_int() function

PHP is_int() function

ᴰᵒᵖᵖᵉˡᵍᵃⁿᵍᵉʳ 多佩尔甘格尔

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

 

Syntax

bool is_int (mixed $var)  

 

Parameters


 

Return type

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

 

Example 1

<?php  
    $x=123;  
    echo is_int($x);  
?>  

 Output


Example 2

<?php   
    $x = 56;   
    $y = "xyz";   
    
    if (is_int($x))   
    {   
        echo "$x is Integer \n" ;   
    }   
    else  
    {   
        echo "$x is not an Integer \n" ;   
    }   
    if (is_int($y))   
    {   
        echo "$y is Integer \n" ;   
    }   
    else  
    {   
        echo "$y is not Integer \n" ;   
    }   
?>  

 Output:


Example 3

<?php   
    
    $check = 12345;  
    if( is_int($check ))   
    {  
            echo $check . " is an int!";  
    }   
    else   
    {  
            echo $check . " is not an int!";  
    }  
    
?>   

 Output:


Report Page