I have the following array from DB.
Now I want to get shin in [user] => shin.
How can I get it with PHP?
Number in [29] => Array could be any number.
Thanks in advance.
Array
(
[29] => Array
(
[0] => stdClass Object
(
[day] => 29
[eventContent] => school ski tada
[eventTitle] => school ski
[id] => 24
[user] => shin
[user_id] => 1
)
[1] => stdClass Object
(
[day] => 29
[eventContent] => north again
[eventTitle] => ski hello
[id] => 26
[user] => shin
[user_id] => 1
)
)
[31] => Array
(
[0] => stdClass Object
(
[day] => 31
[eventContent] => test
[eventTitle] => test
[id] => 21
[user] => shin
[user_id] => 1
)
)
...
...
)
I’m not sure what the array indexes represent but I’ll leave them in just in case they’re useful to you. The answer is basically the same as Alix’s with a check to ensure you actually have a nested array:
Notice the difference between the outer foreach loop and the inner loop. The outer one is retrieving both the array key and value whereas the inner loop is only returning the array value.