Is Int Function in PHP

Introduction

This article explains the "is_int()" function in PHP. The is_int() function determines whether the type of a specified variable is an integer.

Syntax

is_int($var_name);

 

Parameter  
Var name  The variable name of which the type is to be evaluated

When the variable is an integer, true is returned otherwise false.

Example1

Checking a variable to determine if it is an integer or not using "if" and "else" statements. Such as:

<?php

if (is_int(23)) {

    echo "is integer\n";

} else {

    echo "is not an integer\n";

}

?>

Output

Checking Is_int() function.jpg
Example2

<?php   

$var1="234"

$var2=999; 

$var3=698.88; 

$var4=array("a1","a2"); 

$var5=+123456.99;  

$result=is_int($var1); 

echo "[ $var1 is Integer? ]" .var_dump($result)."<br>"; 

$result=is_int($var2); 

echo "[ $var2 is Integer? ]" .var_dump($result)."<br>"; 

$result=is_int($var3); 

echo "[ $var3 is Integer? ]" .var_dump($result)."<br>"; 

$result=is_int($var4); 

echo "[ $var4 is Integer? ]" .var_dump($result)."<br>"; 

$result=is_int($var5); 

echo "[ $var5 is Integer? ]" .var_dump($result); 

?>

Output
Is_int() function.jpg


Similar Articles