An associative array holds a list of data items sequentially that are selected and accessed via a label.
The program below creates an associative array called: $saSaintFeastDays. This array associates the name of a saint with the feast day of the saint.
<?php
$saSaintFeastDays = array("Justin"=>"April 14", "Mark"=>"April 25", "Stephen"=>"December 26");
// Loop over the entries of the array and print them
foreach($saSaintFeastDays as $sSaint => $sDay) {
echo "Key=".$sSaint." | Value=".$sDay."<br>";
echo "The feast day of Saint ".$sSaint." is ".$sDay.".<br><br>";
}
echo "The size of the array is ".count($saSaintFeastDays).".<br><br>";
?>
© 20072024 XoaX.net LLC. All rights reserved.