downloads | documentation | faq | getting help | mailing lists | licenses | wiki | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

Funktionen> <include_once
Last updated: Fri, 30 Oct 2009

view this page in

goto

Der goto-Operator kann benutzt werden um innerhalb eines Programs zu einer anderen Anweisung zu springen. Die Zielanweisung wird durch einen Namen gefolgt von einem Doppelpunkt festgelegt und der goto-Anweisung wird der entsprechende Zielname angefügt.

Beispiel #1 goto-Beispiel

<?php
goto a;
echo 
'Foo';
 
a:
echo 
'Bar';
?>

Das oben gezeigte Beispiel erzeugt folgende Ausgabe:

Bar

Hinweis: Der goto-Operator ist ab PHP 5.3 verfügbar.

Warnung

Es ist nicht gestattet in eine Schleife oder eine Switch-Anweisung hineinzuspringen, in so einem Fall wird ein fataler Fehler geworfen.



add a note add a note User Contributed Notes
goto
chrisstocktonaz at gmail dot com
07-Aug-2009 10:03
Remember if you are not a fan of wild labels hanging around you are free to use braces in this construct creating a slightly cleaner look. Labels also are always executed and do not need to be called to have their associated code block ran. A purposeless example is below.

<?php

$headers
= Array('subject', 'bcc', 'to', 'cc', 'date', 'sender');
$position = 0;

hIterator: {

   
$c = 0;
    echo
$headers[$position] . PHP_EOL;

   
cIterator: {
        echo
' ' . $headers[$position][$c] . PHP_EOL;

        if(!isset(
$headers[$position][++$c])) {
           
goto cIteratorExit;
        }
       
goto cIterator;
    }

   
cIteratorExit: {
        if(isset(
$headers[++$position])) {
           
goto hIterator;
        }
    }
}
?>

Funktionen> <include_once
Last updated: Fri, 30 Oct 2009
 
 
show source | credits | stats | sitemap | contact | advertising | mirror sites