3

What is the best way to determine if something is an array or an object in PHP? I get a response from a web service and it's either an array or an object depending on how many returned results there are. It is impossible to predict ahead of time how many there will be, so I need to figure out how to process it appropriately. What is the best way to do this?

TIA.

4 Answers 4

8

Take a look at the is_object and is_array PHP functions.

Sign up to request clarification or add additional context in comments.

Comments

7

is_array

1 Comment

Well played. JFGI fail on my part. Thanks.
1

Try this:

is_array ($var)

Comments

1

is_array()and is_object()

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.