Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 796163
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T22:35:53+00:00 2026-05-14T22:35:53+00:00

Here is the loop. foreach($results->results as $result){ echo ‘<div id=twitter_status>’; echo ‘<img src=’.$result->profile_image_url.’ class=twitter_image>’;

  • 0

Here is the loop.

foreach($results->results as $result){
    echo '<div id="twitter_status">';
    echo '<img src="'.$result->profile_image_url.'" class="twitter_image">';
    $text_n = $result->text; 
    echo "<div id='text_twit'>".$text_n."</div>";
    echo '<div id="twitter_small">';
    echo "<span id='link_user'".'<a href="http://www.twitter.com/'.$result->from_user.'">'.$result->from_user.'</a></span>';
    $date = $result->created_at;

    $dateFormat = new DateIntervalFormat();

    $time = strtotime($result->created_at);

    echo "<div class='time'>";

    print sprintf('Submitted %s ago',  $dateFormat->getInterval($time));

    echo '</div>';

    echo "</div>";
    echo "</div>";
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T22:35:54+00:00Added an answer on May 14, 2026 at 10:35 pm

    With the break command.

    You are missing a bracket though.

    $i=0;
    foreach($results->results as $result){
    //whatever you want to do here
    
    $i++;
    if($i==3) break;
    }
    

    More info about the break command at: http://php.net/manual/en/control-structures.break.php

    Update: As Kyle pointed out, if you want to break the loop it’s better to use for rather than foreach. Basically you have more control of the flow and you gain readability. Note that you can only do this if the elements in the array are contiguous and indexable (as Colonel Sponsz pointed out)

    The code would be:

    for($i=0;$i<3;$i++){
    $result = $results->results[i];
    //whatever you want to do here
    }
    

    It’s cleaner, it’s more bug-proof (the control variables are all inside the for statement), and just reading it you know how many times it will be executed. break / continue should be avoided if possible.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I don't trust results from jsperf measuring performance of for loop vs forEach. At
I am trying to get a 0 result from this foreach loop but it
First time poster here. A quick question about setting up a loop here. I
I'm learning assembly and I have a very basic loop here segment .data msg:
Here's what I need to do: 1) Loop through every cell in a worksheet
I bet this is loop 101 but here it goes. I am only getting
Here is the case of my Netbeans debugging question: I got a for loop
er,here is a question about netty nioWorker Netty architecture - questions about NioWorker loop
Here is my script... all I want to do is have it continuously loop!
So here's what I see this code doing: An array is made A loop

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.