1$arr = array('one', 'two', 'three', 'four', 'stop', 'five');
2foreach ($arr as $val) {
3 if ($val == 'stop') {
4 break; /* You could also write 'break 1;' here. */
5 }
6 echo "$val<br />\n";
7}
8
9/* Using the optional argument. */
10
11$i = 0;
12while (++$i) {
13 switch ($i) {
14 case 5:
15 echo "At 5<br />\n";
16 break 1; /* Exit only the switch. */
17 case 10:
18 echo "At 10; quitting<br />\n";
19 break 2; /* Exit the switch and the while. */
20 default:
21 break;
22 }
23}
24?>
25
26