CKTIS / PHP
Keyword goto
Transfer execution to a case-sensitive label in the same file and execution context.
Version: PHP 8.4; repository runtime, production runtime not attested
Syntax
goto label; /* ... */ label:Transfer execution to a case-sensitive label in the same file and execution context. A jump can leave nested loops but cannot enter a loop or switch from outside, nor cross a function boundary. An unconditional jump skips intervening statements.
$path=[];
foreach([1,2] as $n){$path[]=$n; if($n===1){goto finished;}}
$path[]="normal"; finished: $path[]="done";
echo json_encode($path);
[1,"done"]
Examples
<?php
$path=[];
foreach([1,2] as $n){$path[]=$n; if($n===1){goto finished;}}
$path[]="normal"; finished: $path[]="done";
echo json_encode($path);
Result
[1,"done"]