PHP – How to check if variable is an array?

PHP has an internal variables handling functions to finds whether a variables is an array


if( is_array($elements) ){
	//do your work

Another fastest way of determining an array is by:
Cast the value to an array, then check using (===) if it is identical to the original.

if ( (array) $elements!== $elements) { 
     echo '$elements is not an array'; 
 } else { 
     echo '$elements is an array'; 

By Keenlio, February 12, 2014

What do you think?

Leave a Reply

Your email address will not be published. Required fields are marked *

one × = 3

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>