Reasons to be mindful of infinite loops
while() Loops
<?php
$a = 0;
while($a < 10) {
echo $a;
$a = $a + 1;
}
?>
<?php
// Same behavior as the while loop
for($a=0; $a < 10; $a++) {
echo $a;
}
?>
<?php
$colors = ['red', 'orange', 'yellow', 'green', 'blue', 'purple'];
foreach($colors as $color) {
echo $color;
}
?>
* Associative arrays assign key and value to temporary variables
<?php
$color_fruit = ['red' => 'apple', 'orange' => 'orange', 'yellow' => 'lemon', 'green' => 'lime', 'purple' => 'plum'];
foreach($colors as $color => $fruit) {
echo "{$fruit} is {$color}.";
}
?>