is_int() : check integer

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.
ctype_digit() FILTER_VALIDATE_INT() is_numeric() intval(): Integer output
PHP Form
Subscribe to our YouTube Channel here


Subscribe

* indicates required
Subscribe to plus2net

    plus2net.com







    gen

    13-07-2012

    how about is not numeric???

    Post your comments , suggestion , error , requirements etc here





    PHP video Tutorials
    We use cookies to improve your browsing experience. . Learn more
    HTML MySQL PHP JavaScript ASP Photoshop Articles FORUM . Contact us
    ©2000-2024 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer