Which PHP function can be used check if variable is an array?

Use the is_array() function. It returns true if the variable is an array and false if it is not.

<?php
var_dump(is_array([1, 2, 3]));
var_dump(is_array("Hello"));
var_dump(is_array(null));
?>

Output:

Tutorials Class - Output Window

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

There are similar functions for other types, like is_string(), is_int() and is_bool(). See how to check the data type of a variable.


Learn more about the similar topics:
Tutorials
PHP Arrays
PHP Array Functions
Exercises & Assignments
Remove specific element by value from an array in PHP?
PHP Array to String Conversion (favourite colours chosen by user)
How to check if an array is a subset of another in PHP?
Interview Questions & Answers
What are the different PHP functions to sort an array?
PHP’s numerically indexed array begins with which position?
Which PHP function inserts an element to the end of an array?
Which PHP function can be used check if variable is an array?
How many types of arrays are available in PHP?
What is the use of array_chunk() function in PHP?
What is the use of in_array() function in PHP?