Advertisement
rodro1

foreach limit loop jeffry Way trick

Jul 16th, 2018
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.14 KB | None | 0 0
  1. $num_tweets = 10;
  2. foreach ($posts as $post) {
  3. if($num_tweets-- == 0) break;
  4. $my_posts[] = $post->title;
  5. }
  6.  
  7. // 10 times loop will run
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement