1   <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
2      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3   
4   <!-- Fig. 26.6: arrays.php -->
5   <!-- Array manipulation -->
6   
7   <html xmlns = "http://www.w3.org/1999/xhtml">
8      <head>
9         <title>Array manipulation</title>
10       </head>
11   
12       <body>
13         <?php
14
15            // create array first
16            print( "<strong>Creating the first array</strong>
17               <br />" );
18            $first[ 0 ] = "zero";
19            $first[ 1 ] = "one";
20            $first[ 2 ] = "two";
21            $first[] = "three";
22   
23             // print each element's index and value
24            for ( $i = 0; $i < count( $first ); $i++ )
25               print( "Element $i is $first[$i] <br />" );
26   
27            print( "<br /><strong>Creating the second array
28               </strong><br />" );
29   
30             // call function array to create array second
31            $second = array( "zero", "one", "two", "three" );
32            for ( $i = 0; $i < count( $second ); $i++ )
33               print( "Element $i is $second[$i] <br />" );
34   
35            print( "<br /><strong>Creating the third array
36               </strong><br />" );
37   
38            // assign values to non-numerical indices
39            $third[ "ArtTic" ] = 21;
40            $third[ "LunaTic" ] = 18;
41            $third[ "GalAnt" ] = 23;
42   
43             // iterate through the array elements and print each
44             // element's name and value
45            for ( reset( $third ); $element = key( $third );
46               next( $third ) )
47               print( "$element is $third[$element] <br />" );
48   
49            print( "<br /><strong>Creating the fourth array
50               </strong><br />" );
51   
52             // call function array to create array fourth using
53             // string indices
54            $fourth = array(
55               "January" => "first", "February" => "second",
56               "March" => "third", "April" => "fourth",
57               "May" => "fifth", "June" => "sixth",
58               "July" => "seventh", "August" => "eighth",
59               "September" => "ninth", "October" => "tenth",
60               "November" => "eleventh","December" => "twelfth"
61               );
62   
63             // print each element's name and value
64            foreach ( $fourth as $element => $value )
65               print( "$element is the $value month <br />" );
66         ?>
67          </body>
68   </html>