W3docs

How to check if variable is array?... or something array-like

In PHP, you can use the "is_array" function to check if a variable is an array.

In PHP, you can use the "is_array" function to check if a variable is an array. For example:

Example of using the "is_array" function to check if a variable is an array in PHP

php— editable, runs on the server

If you want to check if a variable is something array-like, you could use the "is_iterable" function, this function checks if the variable is an array or an object that implements the Traversable interface, starting from PHP 7.1.

Example of using the "is_iterable" function to check if a variable is something array-like in PHP

php— editable, runs on the server

<div class="alert alert-info flex not-prose"> Watch a course <span class="hidden md:block">Watch a video course </span> Learn object oriented PHP</div>

You can also use the instanceof operator to check if the variable is an instance of the ArrayObject or ArrayIterator classes, but it's less recommended.

Example of using the instanceof operator to check if the variable is an instance of the ArrayObject or ArrayIterator classes in PHP

php— editable, runs on the server