As stated in the variables section, variables are containers for your data. For example, I can say that the variable $student is set equal to "Julio Garcia."
$student="Julio Garcia";
I can then tell PHP to print($student); and PHP will print: Julio Garcia.
print($student);
That's easy enough, but I can take things a step further. I can say that:
$student[0]="Alicia Diaz ";
$student[1]="Raul Garcia ";
$student[2]="Rigo Delacruz ";
This kind of variable, a variable that can hold more than one value, is called an array. Therefore, we
can define an array as a collection of values stored under a single variable name. Notice that each
value in the array is numbered. We call this number the index and the value an element.
We can also provide strings (characters) for index values, like so:
$class["seniors"]=200;
$class["juniors"]=200;
$class["sophomores"]=400;
$class["freshmen"]=400;
An easier way to set array values is:
$shoppinglist("milk", "cookies", "cereal", "bread");
This will create an index of 0 through 3 which correspond to each shopping list value, like so:
$shoppinglist[0]="milk";
$shoppinglist[1]="cookies";
$shoppinglist[2]="cereal";
$shoppinglist[3]="bread";
So why are arrays important? We will need to loop through values of the $_REQUEST array in order to
get form values submitted by users.
|