Th PHP continue statement is an expression used to ignore or skip the current code block and move to the next loop. It can be written by this word “continue“.

This expression not exit the loop it only restart the loop for the following field according to the iteration index.

The expression appears and works inside all PHP loops. And it can be written like the below.


The PHP continue statement works with all loops in PHP such as foreach, for loop, while loop, do while loop.

Let’s see how it works.

How the PHP Continue Statement Works

As I mentioned before, the continue expression is skipping the current loop and move to the following one. Check the below figure to understand this process.

PHP Continue Statement

So, the PHP continue expression to prevent the current loop and move it into the next one without execute the current loop statements.

In the next section, you will see that with examples.

PHP Continue Examples

Use the PHP continue with for loop.

  for( $i = 0; $i < 5; $i++ ) {
    if ( $i === 3 ) {
    echo "Loop Index : " . $i;
    echo "\n"; // new line

In this example the for loop will skip the fourth iteration which means will ignore the index number 3. So the output would be like the following.

Loop Index : 0
Loop Index : 1
Loop Index : 2
Loop Index : 4

Also to using the PHP continue with foreach you can use the same way but here I will check about the array key to skip the current item.

   $arr = array(
     "name" => "Montasser",
     "site" => "CodedTag",
     "age"  => 55
   foreach( $arr as $key => $value ){
     if ( $key == 'age' ) {
     echo $value;
     echo "\n"; // new line

This loop will ignore the “age” field of the array. So the result would be like the below.


Wrapping Up

The PHP continue used to skip and move for the following iteration. It is working with any loop in PHP such as while, for loop, and foreach.