CONTINUE

This statement is used to skip to the next iteration of any loops regardless of the remaining code in the current iteration. This is very handy when a specific condition is met halfway through an iteration and the current iteration requires no further processing, so we skip to the next iteration of the loop.

Example

The following code checks the status of each user to print the user's name, and if the user has an inactive status it will skip to the next user.

$users = [
    [
        "id" => "31294",
        "status" => "active",
        "name" => "Alex Garcia"
    ],
    [
        "id" => "90453",
        "status" => "inactive",
        "name" => "Alex Garcia"
    ],
    [
        "id" => "42271",
        "status" => "active",
        "name" => "Alex Garcia"
    ],
]

FOREACH ($users AS $user) {
    IF($user['active'] === 'inactive') {
        CONTINUE
    }
    :: $user['name']
}

Copyright ©2013-2022 SunSed®. All rights reserved.