"Autumn", 2 => "Winter", 3 => "Spring", 4 => "Summer"); print $seasons[1] . " "; print $seasons[2] . " "; print $seasons[3] . " "; print $seasons[4]; echo PHP_EOL . "End of Example 2" . PHP_EOL . PHP_EOL; echo "Example 3 - Set up an array with mixed values" . PHP_EOL; $seasons = array(1 => 10, 2 => "Spring", 3 => 30, 4 => "Summer"); print $seasons[1] . " "; print $seasons[2] . " "; print $seasons[3] . " "; print $seasons[4]; echo PHP_EOL . "End of Example 3" . PHP_EOL . PHP_EOL; echo "Example 4 - Assign array values with PHP chossing next index" . PHP_EOL; $seasons = array(); $seasons[]="Autumn"; $seasons[]="Winter"; $seasons[]="Spring"; $seasons[]="Summer"; print $seasons[0] . " "; print $seasons[1] . " "; print $seasons[2] . " "; print $seasons[3]; echo PHP_EOL . "End of Example 4" . PHP_EOL . PHP_EOL; echo "Example 5 - Creating an array of values with a loop" . PHP_EOL; $start = 1; $times = 2; $answer = array(); for ($start; $start < 11; $start++) { $answer[$start] = $start * $times; } print $answer[1] . " "; print $answer[4] . " "; print $answer[8] . " "; print $answer[10]; echo PHP_EOL . "End of Example 5" . PHP_EOL . PHP_EOL; echo "====================" . PHP_EOL; echo "Press Enter to continue ... "; $discard = fgets(STDIN); echo "Example 6 - Displaying array values with a loop" . PHP_EOL; $seasons = array("Autumn", "Winter", "Spring", "Summer"); for ($key_Number = 0; $key_Number < 4; $key_Number++) { echo $seasons[$key_Number] . PHP_EOL; } echo "End of Example 6" . PHP_EOL . PHP_EOL; echo "Example 7 - Using text as keys to create an associative array" . PHP_EOL; $full_name = array(); $full_name["David"] = "Gilmour"; $full_name["Nick"] = "Mason"; $full_name["Roger"] = "Waters"; $full_name["Richard"] = "Wright"; print $full_name["Nick"] . "\n"; print $full_name["David"]; echo PHP_EOL . "End of Example 7" . PHP_EOL . PHP_EOL; echo "Example 8 - Loop to display associative array key/value pairs" . PHP_EOL; $full_name = array(); $full_name["David"] = "Gilmour"; $full_name["Nick"] = "Mason"; $full_name["Roger"] = "Waters"; $full_name["Richard"] = "Wright"; foreach ($full_name as $first_name => $surname) { print "Key = " . $first_name . " Value = " . $surname . "\n"; } echo "End of Example 8" . PHP_EOL . PHP_EOL; echo "Example 9 - Sorting Arrays (Associative)" . PHP_EOL; $full_name = array(); $full_name["Roger"] = "Waters"; $full_name["Richard"] = "Wright"; $full_name["Nick"] = "Mason"; $full_name["David"] = "Gilmour"; foreach ($full_name as $first_name => $surname) { print "Key = " . $first_name . " Value = " . $surname . "\n"; } ksort($full_name); foreach ($full_name as $first_name => $surname) { print "Key = " . $first_name . " Value = " . $surname . "\n"; } echo "End of Example 9" . PHP_EOL . PHP_EOL; echo "Example 10 - Sorting Arrays (Scalar)" . PHP_EOL; $numbers = array(); $numbers[]="2"; $numbers[]="8"; $numbers[]="10"; $numbers[]="6"; print $numbers[0] . " "; print $numbers[1] . " "; print $numbers[2] . " "; print $numbers[3]; echo PHP_EOL . "End of Example 10" . PHP_EOL; ?>