is_int()

Description

The is_int() function is used to determine if a passed variable is an integer.

Syntax


bool is_int( mixed $var )

Parameters

$var
Variable to test.

Return Value

boolean
A Boolean value is returned as follows:

  • true if passed variable is an integer
  • false if passed variable is not an integer

Examples

1. Check All Types with is_int()

This example creates a variable of each data type and passes it to is_int(). The return value of the is_int() call is passed to var_dump() to display its type and value. Note that the file data.txt exists in the directory so the call to fopen() on line 8 succeeds.

<?php
$boolVal = true;
$intVal = 6;
$floatVal = 3.14;
$stringVal = "Hello";
$arrayVal = array( 1, "two", 3.4 );
$objectVal = new stdClass;
$resourceVal = fopen("./data.txt", "r");
$nullVal = null;

var_dump( is_int( $boolVal ));
var_dump( is_int( $intVal ));
var_dump( is_int( $floatVal ));
var_dump( is_int( $stringVal ));
var_dump( is_int( $arrayVal ));
var_dump( is_int( $objectVal ));
var_dump( is_int( $resourceVal ));
var_dump( is_int( $nullVal ));

fclose($resourceVal);
?>

The output from the program is shown below. Note that only the $intVal variable tests trueinteger.

bool(false)
bool(true)
bool(false)
bool(false)
bool(false)
bool(false)
bool(false)
bool(false)

See Also

is_array
is_bool
is_callable
is_double
is_float
is_integer
is_long
is_null
is_numeric
is_object
is_real
is_resource
is_scalar
is_string
var_dump

[other is_* functions]
var_dump()

References