[PHP-DOC] foreach and break From: Ulf Wendel (ulf <email protected>)
Date: 08/06/00

Hi!

Ok Egon, this time I switched to the snaps:
http://snaps.php.net/manual/en/html/control-structures.break.html. break
seems to work for foreach() eigther, the manual does not mention this.

$array_data = array ( 1 => "one", 2 => "two", 3 => "three" );
foreach($array_data as $value) {
        print "$value<br>";
        if ("one" == $value)
                break;
}

print "<hr>";

foreach($array_data as $value) {
        print "level1, $value<br>";
        foreach($array_data as $key => $value) {
                print "level2, $value<br>";
                if ("one" == $value)
                        break 2;
        }
}

Ulf