Encodera

Thanks for reading!

Donate to the site — we work hard for you.

PHP reference

is_array

Checks whether a value is an array.

Syntax

is_array(mixed $value): bool

Parameters

ParameterTypeDescription
$valuemixedThe value to check.

Return value

bool`true` if the value is an array.

Examples

An array and a string:

<?php
 
var_dump(is_array([1, 2]));
var_dump(is_array('1, 2'));

Output:

bool(true)
bool(false)

A single value or a list of values:

<?php
 
function total($value)
{
    return is_array($value) ? array_sum($value) : $value;
}
 
echo total(5), ' ', total([1, 2, 3]);

Output:

5 6

Notes

There are matching checks for other types: is_string(), is_int(), is_float(), is_bool(), is_callable().

See also

  • gettype — Returns the name of a value's type.
  • count — Returns the number of elements in an array.
  • isset — Checks that a variable exists and is not null.

Related recipes

In the tutorial

  • Data types — The main PHP data types — strings, numbers, booleans, arrays and null.

Thanks for reading!

Donate to the site — we work hard for you.