Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to limit foreach loop to three loops

Tags:

how to limit this loop ..just thee loops..thanks for helping

<?php     foreach($section['Article'] as $article) : ?> <tr>     <td>         <?php             if ($article['status'] == 1) {                 echo $article['title'];             }          ?>     </td>     <td>         <?php             if($article['status']== 1) {                 echo '&nbsp;'.$html->link('View', '/articles/view/'.$article['id']);             }         ?>     </td> </tr> <?php      endforeach;  ?> 
like image 257
user1080247 Avatar asked Jan 06 '12 23:01

user1080247


People also ask

Can you nest foreach loops?

The nesting operator: %:% I call this the nesting operator because it is used to create nested foreach loops. Like the %do% and %dopar% operators, it is a binary operator, but it operates on two foreach objects. It also returns a foreach object, which is essentially a special merger of its operands.

Does Break stop foreach?

break ends execution of the current for , foreach , while , do-while or switch structure.

Is a foreach loop more efficient than a for loop?

The forloop is faster than the foreach loop if the array must only be accessed once per iteration.


1 Answers

Slice the array.

foreach(array_slice($section['Article'], 0, 3) as $article ): 
like image 173
Ignacio Vazquez-Abrams Avatar answered Sep 21 '22 15:09

Ignacio Vazquez-Abrams