5

Take this array as an example

Array
(
[events] => Array
    (
        [0] => Array
            (
                [event] => Array
                    (
                        [category] => seminars,sales
                        [status] => Live

How do I retrieve the value of category? I've tried various combinations such;

echo $array->events->events[0]->event->category;

So simple, yet I just can't figure it out.

Sorry for the lame question.

2
  • 3
    coding is not about combination .. lol Commented Oct 25, 2012 at 14:03
  • 4
    Marvelous Mark. Why the need to troll a genuine question? Commented Oct 25, 2012 at 14:11

4 Answers 4

19

It should be

echo $array['events'][0]['event']['category'];

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

1 Comment

Who knows Probably bored trolls.
7

You are using the object property selector.

Try this:

echo $array['events'][0]['event']['category'] ;

2 Comments

I do not get it, why the down vote? Who does this kind of things, down voting without leaving a comment? I urge SO to change there policy on this!
I had converted it from a object to an array previously, thank you for mentioning that.
2

Try echo $array['events'][0]['event']['category'];

Comments

1

Like this:

echo $arr['events'][0]['event']['category'];

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.