php is variable an array or object

Issue

Trying to figure out how to do the equivalent of something I did in javascript but in php. But I’m not sure of the operators to do it. In javascript I wanted to see if a particular parameter being passed was either an object or array.. and if not then was it a string/int and what I did was something like

if (str instanceof Array || str instanceof Object) 
{
   //code
}
else
{
   //code
}

anyone know of the equivalent to this for php?

Solution

Use is_array to check if a variable is an array, and similarly, use is_object to check if a variable is an object.

Answered By – Ry-

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published