2

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!

3 Answers 3

2
foreach($tweets as $tweet) {
    echo $tweet->text;
    echo $tweet->user->screen_name;
}
Sign up to request clarification or add additional context in comments.

Comments

2

try:

foreach($array as $a) {
  $text = $a->text;
  $screen_name = $a->user->screen_name;
}

Comments

2

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.