In a PHP while loop, an expression is evaluated before the statements. In a do while loop, however, the expression is evaluated at the end of the loop.

PHP While Loop

In a PHP while loop, an expression is evaluated before the statements. In a do while loop, however, the expression is evaluated at the end of the loop.

Let's create an array and keep looping until we reach the end of the loop so we can print out all the values of the array:

$animals = array('Antelope','Bat','Bear','Dolphin','Goose','Vulture'); $key = 0; $total = count( $animals ); //using while loop while ( $key < $total ) { echo $animals[ $key ].' '; $key++; } //output: Antelope Bat Bear Dolphin Goose Vulture //using do { } while loop $key = 0; do { echo $animals[ $key ].' '; $key++; } while ( $key < $total ); //output: Antelope Bat Bear Dolphin Goose Vulture