<?php
$teste = array(1,2,3,4,5);
foreach($teste as $t){
switch($t){
case 1:
echo "Terminando loop ao achar o número 1<br>";
break(2); // Finaliza o switch e o for
case 2:
echo "Terminando loop ao achar o número 2<br>";
break;
case 3:
echo "Terminando loop ao achar o número 3<br>";
break;
default:
echo "Terminando loop, nenhum número foi achado<br>";
}
}
echo "fim de script";
PD9waHAKCiR0ZXN0ZSA9IGFycmF5KDEsMiwzLDQsNSk7Cgpmb3JlYWNoKCR0ZXN0ZSBhcyAkdCl7Cglzd2l0Y2goJHQpewoJCWNhc2UgMToKCQkgIGVjaG8gIlRlcm1pbmFuZG8gbG9vcCBhbyBhY2hhciBvIG7Dum1lcm8gMTxicj4iOwoJCSAgYnJlYWsoMik7IC8vIEZpbmFsaXphIG8gc3dpdGNoIGUgbyBmb3IKCQljYXNlIDI6CgkJICBlY2hvICJUZXJtaW5hbmRvIGxvb3AgYW8gYWNoYXIgbyBuw7ptZXJvIDI8YnI+IjsKCQkgIGJyZWFrOwoJCWNhc2UgMzoKCQkgIGVjaG8gIlRlcm1pbmFuZG8gbG9vcCBhbyBhY2hhciBvIG7Dum1lcm8gMzxicj4iOwoJCSAgYnJlYWs7CgkJZGVmYXVsdDoKCQkgIGVjaG8gIlRlcm1pbmFuZG8gbG9vcCwgbmVuaHVtIG7Dum1lcm8gZm9pIGFjaGFkbzxicj4iOwoJfQp9CmVjaG8gImZpbSBkZSBzY3JpcHQiOw==