how to limit foreach loop to three loops

后端 未结 6 2329
梦如初夏
梦如初夏 2020-12-13 10:31

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



    
               


        
6条回答
  •  萌比男神i
    2020-12-13 11:30

    This will help if your array is numerically indexed

    foreach($section['Article'] as $i => $article ):
    
        if ($i > 3) break;
    

    Otherwise - manually increment the counter:

    $i = 0;
    foreach($section['Article'] as $article ):
    
        if ($i++ > 3) break;
    

提交回复
热议问题