This site is mobile accessible. Press the "Tap Here" button to use a different font-size.


Smartphone icons created by Freepik - Flaticon

PHP Loops

The PHP foreach Loop

Peter is 35 years old.
Ben is 37 years old.
Joe is 43 years old.

<?php
// create $age array
$age = array("Peter"=>"35", "Ben"=>"37", "Joe"=>"43");

// run foreach loop on the $age array and select $val for each item in the array
foreach($age as $x => $val) {

// displays the values of each item in the array
  echo "$x is $val years old.<br>";
}
?>