php parse array in array
I've got an array that looks like this, but much longer:
Array
(
[0] => stdClass Object
(
[text] => @TwitterUser. Lorem Ipsum
[id_str] => 60768083157061632
[user] => stdClass Object
(
[profile_image_url] => http://a0.twimg.com/sticky/default_profile_images/default_profile_3_normal.png
[screen_name] => MyDude
I want to print only certain values per key in this array. So, all values for the keys [text]
and开发者_如何转开发 [screen_name]
in parent keys [0]
through [whatever]
. I feel like I should do something like a $foreach
statement, but can't quite figure out how to tell my machine to look down through the child arrays in each of the numerical parent keys.
Any help would be much appreciated!
foreach($tweets as $tweet) {
echo $tweet->text;
echo $tweet->user->screen_name;
}
try:
foreach($array as $a) {
$text = $a->text;
$screen_name = $a->user->screen_name;
}
That's pretty basic.
foreach ($array as $tweet) {
echo $tweet->text . '<br>';
echo $tweet->user->screen_name;
}
You might want to do a check before echoing though
精彩评论