is_int()

By using is_int function we can check integer number in PHP. This function returns True of false ( Boolean variable ) based on the data. Here is an simple example
$var=5;
if(is_int($var)){
echo " this is an integer ";// This is the output 
}else{
echo " this is not an integer ";
}
Example :
For True output is 1 , For False no output will be generated.
<?php
$var=5;
echo is_int($var); // Output 1 
echo "<br>";
$var='5';
echo is_int($var); // No Output  
echo "<br>";
$var=5.8;
echo is_int($var); // No output (for Float)  
echo "<br>";
$var=+5;
echo is_int($var); // Output 1 
echo "<br>";
$var=-5;
echo is_int($var); // Output 1 
echo "<br>";
$var='a123';
echo is_int($var); // No output  
echo "<br>";
?>

Difference between is_numeric and is_int

if the variable stores integer as string that then is_int() will return false. Here is an example.
$var="123";
if(is_int($var)){
echo " this is an integer ";
}else{
echo " this is not an integer ";}
Above code will say this is not an integer
But in above case is_numeric will identify this as an integer. Note that if we are using any form data as input then all numeric data also treated as string. Here is an example.
$var=$_POST['t1'];
if(is_int($var)){
echo " this is an integer ";
}else{
echo " this is not an integer ";
}
We can create an form to post data to the above code like this
<form method=post action=is_int1.php>
<input type=text name=t1>
<input type=submit value=submit>
In the above form if we post an integer then also is_int will return false.
Visitors Rating
Your Rating





gen

13-07-2012

how about is not numeric???

Post your comments , suggestion , error , requirements etc here .




HTML MySQL PHP JavaScript ASP Photoshop Articles FORUM . Contact us
©2000-2019 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer