PHP Loops
In PHP, loops are used to execute a block of code repeatedly under certain conditions. PHP supports several types of loops:
1. for
Loop
Used when the number of iterations is known.
2. while
Loop
Executes as long as a specified condition is true.
3. do...while
Loop
Executes the code block once, then repeats as long as the condition is true.
4. foreach
Loop
Used to loop through arrays.
For associative arrays: