PHP Arrays


There are three different kinds of arrays: Numeric Arrays

Example I
Example II
 $names = array( "Peter", 
    "Quagmire", "Joe" );
 $names[0] = "Peter";
 $names[1] = "Quagmire";
 $names[2] = "Joe";


A numeric array stores each element with a numeric ID key. There are different ways to create a numeric array. In the above examples, the Example I is the same as the Example II.
 <html><body>
 <?php
   $size = ;
   for ( $i = 0; $i < $size; $i++ )
     $array[$i] = $i;
   $total = 0;
   for ( $i = 0; $i < $size; $i++ )
     $total += $array[$i];
 ?>
 </body></html>
$total =    
Associative Arrays
When storing data about specific named values, a numerical array is not always the best way to do it. With associative arrays we can use the values as keys and assign values to them. In the following examples, the Example III is the same as the Example IV.

Example III
Example IV
 $ages = array( "Peter" => 32,
   "Quagmire" => 30, "Joe" => 34 );
 $ages['Peter'] = "32";
 $ages['Quagmire'] = "30";
 $ages['Joe'] = "34";




      Boy: Wanna hear a joke?    
      Girl: No thanks. I’m already looking at one.