PHP Goto Statement
ADVERTISEMENTS
PHP goto operator is used to jump to another section or area of the program.
Syntax of the php goto operator
goto label; // Label is the target to jump
some code goes here; // This code is be skipped
label: // Target will start from this label
new code goes here; // This code is be executed
Understand goto operator from this example:
<?php
goto m;
echo "It's the bad program\n";
m:
echo "It's the good program\n";
?>
Output:
It's the good program
The disadvantage of the goto operator:
- The target label must be within the same file and context it's necessary
- you cannot jump out of a function
- you cannot jump out of a method
- you can not jump into a sort of loop
- you can not jump into the switch loop