PHP Function Reference

PHP is_array() Function



The PHP is_array() function checks whether a variable is an array. The function returns true if the variable is an array, otherwise it returns false.

Syntax

is_array(variable)

Parameters

variable Required. Specify the variable being evaluated.

Return Value

Returns true if variable is an array, false otherwise.

Example:

The example below shows the usage of is_array() function.

<?php
$x1 = array(10, "Hello", true);
$x2 = array();
$x3 = array(10, array(true, false));
$x4 = [10, "Hello", true];
$x5 = "Hello";
$x6 = 10.5;
$x7 = true;
$x8 = null;

var_dump(is_array($x1));   //returns: bool(true)
var_dump(is_array($x2));   //returns: bool(true)
var_dump(is_array($x3));   //returns: bool(true)
var_dump(is_array($x4));   //returns: bool(true)

echo "\n";

var_dump(is_array($x5));   //returns: bool(false)
var_dump(is_array($x6));   //returns: bool(false)
var_dump(is_array($x7));   //returns: bool(false)
var_dump(is_array($x8));   //returns: bool(false)
?>

The output of the above code will be:

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

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

❮ PHP Variable Handling Reference