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'];
Author by
cee.e
Updated on June 14, 2022Comments
-
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 over 11 yearsI 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 over 11 yearsI had converted it from a object to an array previously, thank you for mentioning that.
-
nickhar over 11 yearsWho knows Probably bored trolls.