Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 236
cee.e Avatar asked Oct 25 '12 14:10

cee.e


4 Answers

It should be

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

like image 88
Muthu Kumaran Avatar answered Nov 15 '22 05:11

Muthu Kumaran


You are using the object property selector.

Try this:

echo $array['events'][0]['event']['category'] ;
like image 22
JvdBerg Avatar answered Nov 15 '22 03:11

JvdBerg


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

like image 29
undefined Avatar answered Nov 15 '22 05:11

undefined


Like this:

echo $arr['events'][0]['event']['category'];
like image 20
Nelson Avatar answered Nov 15 '22 05:11

Nelson