How can one interrupt a foreach loop multiple times in PHP?

To interrupt a foreach loop multiple times in PHP, you can use the 'break' statement within the loop to exit prematurely. By using a counter variable or a condition, you can control how many times the loop should be interrupted. Each time the condition is met, you can break out of the loop.

$counter = 0;
$array = [1, 2, 3, 4, 5];

foreach ($array as $value) {
    if ($counter >= 2) {
        break;
    }
    
    // Perform some operations
    
    $counter++;
}