Logo

Programming-Idioms

History of Idiom 42 > diff from v27 to v28

Edit summary for version 28 by empyrical:
New PHP implementation by user [empyrical]

Version 27

2016-09-23, 13:28:11

Version 28

2017-04-13, 12:08:50

Idiom #42 Continue outer loop

Print each item v of list a which in not contained in list b.
For this, write an outer loop to iterate on a and an inner loop to iterate on b.

Illustration

Idiom #42 Continue outer loop

Print each item v of list a which in not contained in list b.
For this, write an outer loop to iterate on a and an inner loop to iterate on b.

Illustration
Code
$array_1 = [1,2,3,4,5];
$array_2 = [3,4];

foreach ($array_1 as $a) {
    foreach ($array_2 as $b) {
        if ($b == $a) {
            continue 2;
        }
    }
    echo $a
}
Comments bubble
The number next to the continue statement determines how many loops "up" it should skip. continue 1 is the same as continue with no numerical argument passed, and will skip to the next iteration of the current loop.
Doc URL
http://php.net/manual/en/control-structures.continue.php