PHP Break Statement in Loops
Syntax
The break statement in PHP exits the current loop when a specific condition is met.
// Using break in a loopforeach ($array as $value) { if (condition) { break; // Exit the loop } // Code to execute if condition is not met}Example
// Break out of a loop when a condition is metfor ($i = 1; $i <= 10; $i++) { if ($i == 5) { break; // Exit the loop when $i is 5 } echo $i . "\n";}/* Output:1234*/