Goto Statement in PHP

How does the goto statement work?

Explanation

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

Syntax:


<?php
goto label;
?>

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

Example :


<?php
goto b;
echo 'Hello';
b:
echo 'World';
?>
Result :

World

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