Arrays have been used traditional to grab blocks of memory in order to hold similiar data, the grades example above is a good one. In the dark ages before object oriented programming languages, arrays were the savior of many a savvy programmer alleviating him of excess typing by applying simple formulas to many pieces of data with iterative structures. The array is a simple yet powerful concent that is an integral part of all programming languages (at least that I can think of.)
Example 1: (non array approach)
Let's say I am a fruit salesperson and I offer
apples, oranges, tangerines, watermelons and grapes
I could set the prices up by explicitly defining them...(prices arbitrary)
$apple = .50;
$orange = .75;
$tangerine = .40;
$watermelon = .80;
$grapes = 1.20;
now lets say hurricane katrina causes a 20% jump in all prices of my precious fruit.
$apple = .2;
$orange = .2;
$tangerine = .2;
$watermelon = .2;
$grapes *= .2;
still not to bad, now imagine 1000 fruits!
The solution (well an answer at least)
Array approach.
$MyFruits = array("apples", "oranges", "tangerines", "watermelons","grapes");
$MyPrices = array(.50, .40, .75, .80, 1.20);
for ( $i=0; $i<count($MyPrices); $i++){
$MyPrices[$i] *= .2;
}
Good for 5 to a 'zillion, nuff said?