PHP is_array() Function

Beginner
5 min read
Updated: Nov 2026
3 examples
Variables

Definition

In PHP, is_array() checks whether a variable is an array. It returns true for arrays and false for every other type.

Use it before you loop over data or call array functions, when you are not sure what a variable holds. Objects that behave like arrays, such as ArrayObject, are not arrays, so is_array() returns false for them.

Syntax

Call is_array() with the values you need. Start with this line.

PHP
$result = is_array($value);
CallWhat it does
is_array([1, 2, 3])Returns true, because the value is an array.
is_array("1,2,3")Returns false, because the value is a string.
is_array(null)Returns false, because null is not an array.

An empty array is still an array, so is_array([]) is true. If you also want to accept objects that act like arrays, use is_iterable() or is_countable() instead.

Library declarations
PHP
is_array(mixed $value): bool

Parameters

ParameterDescription
valueRequired. The variable or value to test.

Return Value

Return ValueDescription
booltrue if the value is an array, otherwise false.

PHP Examples

Example 1 — Checking Different Values

Test an array and three non-array values.

PHP
<?php
var_dump(is_array([1, 2, 3]));
var_dump(is_array("text"));
var_dump(is_array(5));
var_dump(is_array(null));

How It Works

  1. [1, 2, 3] is an array, so the first call returns true.
  2. A string, even if it contains list-like text, is not an array.
  3. A number is not an array.
  4. null is not an array either.

Example 2 — Empty Arrays and Array-Like Objects

Some values look like arrays but are not, and an empty array is still an array.

PHP
<?php
var_dump(is_array([]));
var_dump(is_array(new ArrayObject([1, 2])));
var_dump(is_array("[1,2,3]"));
var_dump(is_array(array()));

How It Works

  1. An empty array [] is still an array, so the result is true.
  2. ArrayObject acts like an array, but it is an object, so is_array() returns false.
  3. The string "[1,2,3]" only looks like a list. It is a string, so the result is false.
  4. array() is the older way to write an array and gives true, just like [].

Example 3 — Accepting One Item or Many

A common pattern is to accept either a single value or a list, and turn a single value into a list.

PHP
<?php
function total($items) {
    if (!is_array($items)) {
        $items = [$items];
    }
    return array_sum($items);
}

echo total([1, 2, 3]), PHP_EOL;
echo total(5), PHP_EOL;
echo total("7"), PHP_EOL;

How It Works

  1. The function can receive either an array or a single value.
  2. If $items is not an array, it is wrapped in a new array with one item.
  3. array_sum() then works the same way for both cases.
  4. total([1, 2, 3]) adds three numbers, while total(5) and total("7") each add a single value.

Frequently Asked Questions

is_array() returns true if a variable is an array and false for any other type, such as a string, number, boolean, null or object.
Yes. is_array([]) returns true. To check whether an array has items, use empty($array) or count($array) > 0.
No. ArrayObject is an object, even though you can use it like an array. Use is_iterable() or is_countable() if you also want to accept array-like objects.
Write if (is_array($data)) { foreach ($data as $item) { ... } }. This avoids warnings when the variable is null or a string.
is_array() is true only for arrays. is_iterable() is true for arrays and for objects that implement Traversable, such as generators and ArrayObject.

Next: is_bool()

is_bool() checks whether a variable is a boolean. It returns true only for the values true.

is_bool() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

8 people found this page helpful