Repeats a block code as long as a condition is met.
A while loop is often useful when a block of code needs to be repeated a number of times that is not known in advance.
<?php
$fruits = array("apple", "banana", "orange");
while ($fruit = current($fruits)) {
print "$fruit ";
next($fruits);
}
?>
apple banana orange
The code shows how a while loop can be used to go through all elements in an array.