Goto Statement in PHP

How does the goto statement work?


Goto label is used to jump code execution to different set of code in a program.


goto label;

The syntax of "goto" statement is with a label and a semicolon.

Example :

goto b;
echo 'Hello';
echo 'World';
Result :


In the above example, when the code encounters the goto statement, the control moves based on the label "b",which in turn displays "World" alone.

Note :

This goto structure works fine in PHP Ver 5.3 and above.

PHP Topics

Ask Questions

Ask Question