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

snippet
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

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

Output:

PHP Variable Handling is_int() function

Example 2

snippet
<?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:

PHP Variable Handling is_int() function

Example 3

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

Output:

PHP Variable Handling is_int() function

Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials

Preparation

Trending Technologies

B.Tech / MCA

Related Tutorial
Follow Us
https://www.facebook.com/Rookie-Nerd-638990322793530 https://twitter.com/RookieNerdTutor https://plus.google.com/b/117136517396468545840 #
Contents