How to stop a loop PHP

后端 未结 4 712
没有蜡笔的小新
没有蜡笔的小新 2021-01-29 06:10

I\'m trying to figure out if its possible to stop a foreach loop in PHP, like this,

$arr = array(\'Joe\', \'Jude\', \'James\', \'Pitch\', \'Tim\');
$i=0;
foreach         


        
4条回答
  •  既然无缘
    2021-01-29 07:14

    You can use good old keyword break here as well. Followed by a semicolon ; of course.

    if($i == 2){
         break;
    }
    

    Manual for break

提交回复
热议问题