How to echo single value from multidimensional array when key is numeric?

15,809

Solution 1

It should be

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

Solution 2

You are using the object property selector.

Try this:

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

Solution 3

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

Solution 4

Like this:

echo $arr['events'][0]['event']['category'];
Share:
15,809
cee.e
Author by

cee.e

Updated on June 14, 2022

Comments

  • cee.e
    cee.e almost 2 years

    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.

  • JvdBerg
    JvdBerg over 11 years
    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!
  • cee.e
    cee.e over 11 years
    I had converted it from a object to an array previously, thank you for mentioning that.
  • nickhar
    nickhar over 11 years
    Who knows Probably bored trolls.