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 |