Guide to PHP and MySQL (University at Buffalo Version)
Chapter 5: Using PHP Loops
PHP provides a few different control structures that allow you to loop through data using a set of statements.
The PHP for Loop
The for statement provides a way to loop through a statement, or group of statements, a number of times.
The PHP foreach Loop
The foreach loop statement provides a way to "walk" through an associative array.
The PHP while Loop
The while loop statement provides a way to to perform a statement or statements based on a condition being true or false.
The PHP do / while Loop
The do ... while loop statements provide a way to to perform a statement or statements based on a condition being true or false. A do ... while loop tests the condition at the end of the loop. So, a do ... while loop will always execute at least once.