is_array
Checks whether a value is an array.
Syntax
is_array(mixed $value): boolParameters
| Parameter | Type | Description |
|---|---|---|
| $value | mixed | The 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 6Notes
There are matching checks for other types: is_string(), is_int(), is_float(), is_bool(), is_callable().
See also
Related recipes
In the tutorial
- Data types — The main PHP data types — strings, numbers, booleans, arrays and null.