PHP break and continue statements are used to dominate or control PHP loop statements and PHP goto statement is used to jump one execution label to another execution label. There is no alternative to control PHP for loop, while loop and foreach loop without PHP break and PHP continue statements. So, PHP programmer should learn PHP break and continue statements deeply otherwise he/she cannot be expert enough on PHP loop statements.
In my previous article, I explained PHP loop statements elaborately and in this article I am going to discuss PHP break, continue and goto statements elaborately.

break Statement in PHP
PHP break statement can terminate PHP loop statements immediately. When for loop, foreach loop or while loop faces break keyword, it terminates its loop execution and program control goes to next statement. So, we should be careful enough to place break keyword within a PHP conditional statement. Otherwise PHP loop statements will not be performed properly.
PHP break Statement Example
The following program is a tiny example of PHP while break statement. Here, the break keyword is being used to terminate a while loop under a certain within condition.
<?php
$i=0;
while($i<10){
if($i==5){
break;
}
echo $i++.' ';
}
Output
From the above program we can see that the while loop is being executed only five times (due to face break statement) although it has been declared to execute ten times.
continue Statement in PHP
PHP continue statement starts a new loop without executing the current loop body. When a loop finds continue keyword, it stops the body execution and restarts the loop. So, we should be careful to use PHP continue inside a conditional statement otherwise loop body will never be executed and desired output cannot be found.
PHP continue Statement Example
The following program is a tiny example of PHP while continue statement where the continue keyword is being used to skip a while loop body under a certain condition.
<?php
$i=0;
while($i<10){
if($i==5){
continue;
}
echo $i++.' ';
}
?>
Output
From the above program we can see that when variable $i is equal to 5, the continue statement is being executed. So, the execution of loop body is ignored and 5 is not printed with the echo function.
In real PHP application we may face such a situation where continue statement must use. For example, we want to get all users without admin. Our database query will fetch all users available in our application. So, we need to filter the admin user inside the loop body. If admin is appeared, the execution of loop body will be ignored. This algorithm can be applied with the PHP continue statement.
The following program is a example of PHP foreach continue where the body of a foreach loop is being ignored with the continue statement when user equal to admin.
<?php
$users=array("David","Bob","admin","Jack","Baily");
foreach($users as $user){
if($user=='admin'){
continue;
}
echo($user.' ');
}
?>
Output
From the output we can see that the admin user is not present because when user will be admin, continue statement will be executed and the loop body will be skipped.
goto Statement in PHP
PHP goto statement is used to jump one execution label to another execution label. If we need to jump our program to a labeled statement, we can use goto statement. For example, we need to provide extra information for admin user and less information for other users. In this case we can use goto statement to solve this problem.
PHP goto Statement Example
The following program is a simple example of PHP goto statement where admin user will get extra information but general user will get less information.
<?php
$user='David';
if($user !="admin"){
goto general_user;
}
echo "Hey, this admin area. General user cannot access here";
general_user:
echo "This area is common for both admin and general user";
?
Output
From the output we can see that only the general user part is executing because the user is not admin user. For the admin user, both echo functions will be executed and both echo result will be printed. Try yourself with user equal to admin and verify the result.
PHP break, continue and goto statement has been explained in this article. I hope, you will now be able to PHP break, continue and goto statements whenever requires. However, if you face any confusion to use break, continue and goto statement properly, feel free to discuss in comment or contact me from Contact page. I will try my best to stay with you.
Finally someone who gives a good example of the use of GOTO in PHP. Thanks Abu Sayed!