Home > Article > Backend Development > The role of break in php
break is a reserved word in some computer programming languages, and its function is to terminate the loop at the current level in most cases. In the switch (switch statement) of C language, the break statement can also be used to jump out of the current switch structure immediately after executing a case (branch). In the process of debugging some programs, break is used to set breakpoints. Next we will introduce the role of break in PHP.
Recommended tutorial: PHP video tutorial
##break ends the current for, foreach, while, do- Execution of while or switch structure.
break can accept an optional numeric parameter to determine how many loops to break out of.
/n"; } /* Using the optional argument. */ $i = 0; while (++$i) { switch ($i) { case 5: echo "At 5
/n"; break 1; /* Exit only the switch. */ case 10: echo "At 10; quitting
/n"; break 2; /* Exit the switch and the while. */ default: break; } } ?>
The above is the detailed content of The role of break in php. For more information, please follow other related articles on the PHP Chinese website!