经测试代码如下:
/**
* 循环一定次数后终止循环
*
* @param
* @arrange (512.笔记) jb51.cc
**/
$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
}
/*** 来自编程之家 jb51.cc(jb51.cc) ***/