php - How to loop through a specific depth in an array? -
i'm pulling json information , i'm left huge nested array.
an example schema follows:
'messages' => '0' => 'title' => 'foo' 'body' => 'bar' '1' => ... 'stories' 'foo' => 'bar'
in scenario, want grab contents starting '0' , '1' , of children (title , body). 'stories' disregarded 1 depth higher 0 , 1. 0 , 1 automatically generated list , integer value dynamically go high need be, different.
cheers!
foreach($array['messages'] $key => $val){ if($key == 0 or $key == 1){ $new_array[] = $val; } }
$new_array
have relevant content. assumes you're referring messages
part of array. if there other sub arrays want parse/manipulate have adjust condition in foreach loop.
you can parse/manipulate $new_array
needed, , ignore content don't need in $array
.
Comments
Post a Comment