PHP is integer

Education is not limited to just classrooms. It can be gained anytime, anywhere... - Ravi Ranjan (M.Tech-NIT)

PHP : is_integer() function

Description

The is_integer() function is used to test whether the type of the specified variable is an integer or not. This function is an alias of is_int().

Version

(PHP 4 and above)

Syntax

is_integer(var_name)

Parameter

Name

Description

Required /
Optional

Type

var_name

The variable being checked

Required

Mixed*

*Mixed : Mixed indicates that a parameter may accept multiple (but not necessarily all) types.

Return value

TRUE if var_name is an integer, FALSE otherwise.

Value Type : Boolean.

Example :

  1. $var_name1=678;  

  2. $var_name2="a678";  

  3. $var_name3="678";  

  4. $var_name4=999;  

  5. $var_name5=698.99;  

  6. $var_name6=array("a1","a2");  

  7. $var_name7=+125689.66;  

  8. if (is_integer($var_name1))  

  9. {  

  10. echo "$var_name1 is Integer
    " ;  

  11. }  

  12. else  

  13. {  

  14. echo "$var_name1 is not an Integer
    " ;  

  15. }  

  16. if (is_integer($var_name2))  

  17. {  

  18. echo "$var_name2 is Integer
    " ;  

  19. }  

  20. else  

  21. {  

  22. echo "$var_name2 is not Integer
    " ;  

  23. }  

  24. $result=is_integer($var_name3);  

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

  26. $result=is_integer($var_name4);  

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

  28. $result=is_integer($var_name5);  

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

  30. $result=is_integer($var_name6);  

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

  32. $result=is_integer($var_name7);  

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

  34. ?>  

Output :

678 is Integer
a678 is not Integer
bool(false) [ 678 is Integer? ]
bool(true) [ 999 is Integer? ]
bool(false) [ 698.99 is Integer? ]
bool(false) [ Array is Integer? ]
bool(false) [ 125689.66 is Integer? ]