is_array()

Description

The is_array() function is used to determine if a passed variable is an array.

Syntax


bool is_array( mixed $var )

Parameters

$var
Variable to test.

Return Value

boolean
A Boolean value is returned as follows:

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

Examples

1. Check All Types with is_array()

This example creates a variable of each data type and passes it to is_array(). The return value of the is_array() 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_array( $boolVal ));
var_dump( is_array( $intVal ));
var_dump( is_array( $floatVal ));
var_dump( is_array( $stringVal ));
var_dump( is_array( $arrayVal ));
var_dump( is_array( $objectVal ));
var_dump( is_array( $resourceVal ));
var_dump( is_array( $nullVal ));

fclose($resourceVal);
?>

The output from the program is shown below. Note that only the $arrayVal variable tests true as an array.

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

See Also

  • is_array() – Determines whether an expression is an array
  • is_bool() – Determines whether an expression is a boolean
  • is_callable() – Verifies that an expression can be called as a function
  • is_double() – Alias of is_float()
  • is_float() – Determines whether the type of an expression is float
  • is_int() – Determines whether the type of an expression is integer
  • is_integer() – Alias of is_int()
  • is_long() – Alias of is_int()
  • is_null() – Determines whether an expression is NULL
  • is_numeric() – Determines whether an expression is a number or a numeric string
  • is_object() – Determines whether an expression is an object
  • is_real() – Alias of is_float()
  • is_resource() – Determines whether an expression is a resource
  • is_scalar() – Determines whether an expression is a scalar
  • is_string() – Determines whether an expression is a string

References