一个通过break语句终止php循环的例子
$max_loop=5; //This is the desired value of Looping $count = 0; //First we set the count to be zeo echo "<h2> Here goes the values</h2>"; foreach($my_array as $key => $val) { echo "The value of $key is $val<br/>"; //Print the value of the Array $count++; //Increase the value of the count by 1 if($count==$max_loop) break; //Break the loop is count is equal to the max_loop }