Array Related Built-in Functions
<< Arrays - Ordered Maps
<< PHP Tutorials - Herong's Tutorial Examples
This section provides a tutorial example on how to create arrays in different ways.
PHP offers a number of interesting built-in functions to work with arrays:
PHP also offers special loop statements to iterate over arrays:
foreach($myArray as $value) {} foreach($myArray as $key=>$value) {}
Here is a simple script with a "foreach" statement:
<?php # ArrayLoop.php # Copyright (c) 2003 by Dr. Herong Yang # print "\nLibrary hours:\n"; $libraryHours = array( 'Monday - Friday'=>'09:00 - 21:00', 'Saturday'=>'09:00 - 17:00', 'Sunday'=>'closed'); foreach($libraryHours as $day=>$hours) { print " $day: $hours\n"; } ?>
Here is the output:
Library hours: Monday - Friday: 09:00 - 21:00 Saturday: 09:00 - 17:00 Sunday: closed
Last update: 2005.
Sections in This Chapter
What Is an Array?
Creating Arrays - Examples