代码如下: $array = array(1,2,3,4,5,6); for($i=0;$i foreach($array as $key) { echo $key; if($key==2){ break 2; } } }