PHP goto
PHP goto is used to perform the task of program jump. When writing C language, goto is a commonly used technique, but it is not commonly used in PHP . Goto has some restrictions in PHP , and it can only be in a certain context in the same file. , Which means that you cannot jump out of the same file, function or method to execute other programs, and of course you cannot jump into another file, function or method. Although the restriction is stricter than in the C language, it is used to jump out of the loop or The switch is quite convenient. The concept of goto has been used in C language for a long time, and PHP, which is derived from C language, finally has this concept. The development of PHP is really getting stronger and stronger.
PHP goto syntax example
goto section2;
echo 'section1';
section2:
echo 'section2';
?>
PHP goto out of the loop example
for ( $i=0 ; $i<20 ; $i++ ){
if( $i==5 ) goto END;
}
echo " i = $i ";
END:
echo ' 變數 i 達到 5 囉!';
?>
Note: PHP goto can only be used on PHP 5.3 and newer versions.
Post a Comment
0 Comments