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?
PHP

Avatar of undefined
Last Comment
elepil

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Dave Baldwin

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
SOLUTION
Ray Paseur

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
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.
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.
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck