Link to home
Start Free TrialLog in
Avatar of elepil
elepil

asked on

PHP, how to use instanceof on an array

I did a var_dump on a variable called $row, and I got this:

array (size=1)
  'name' => string 'Glenn' (length=5)

Open in new window


So I know it is an array. But when I do this:

echo $row instanceof array;

Open in new window


I get a syntax error: Parse error: syntax error, unexpected 'array' (T_ARRAY).

Now I know there is the is_array, but is there no way I can use instanceof on an array?
ASKER CERTIFIED SOLUTION
Avatar of Dave Baldwin
Dave Baldwin
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of elepil
elepil

ASKER

It was Dave's answer that led me to the answer when he said 'array' is a type.

Both of you have helped me a lot to date, and I wonder if the days are gone when I'd ask a question and get a very specific answer. It seems I've been getting a slew of links that point to generalities lately, especially from Ray.

Both your responses did help though, but I had to spend a bit more time going through your links. I now know I have to use gettype() first, and if it says object, then I can use getclass() to determine what class it is. gettype() would've also returned 'array' if the variable were an array, which was what I was looking for. Had responses run along these lines, I would've given an 'A' for the solution.

Thank you both for your help.
Avatar of elepil

ASKER

The definition of 'A' grade says "or is a link to information that answered the question". While that is technically correct, you really do take advantage of that as you always give me links that go way beyond the scope of my question. But just because the needle resides in one of the haystacks does not necessarily make a good answer.

I frown upon your practice of changing the grade; this would be the third time you've done this to me. I will have to talk to EE's customer service personnel about this.