Welcome to my series on every PHP keyword and its usage. Today’s item:
goto statement allows you to jump around in the current context, disregarding normal code flow. Using
goto should be avoided in most situations, as it makes it harder to reason about your code.
goto is restricted to the current file, and the current context. This means that you can not jump to another file, nor can you jump into or out of a function.
In most situations where you might be tempted to use
goto, you should consider either using a loop, or refactoring into a function. Using
goto can have negative results:
Comic courtesy of xkcd
If you must use
Author Callum Muir