|
Arrays 101
Multi-dimensional arrays. Sounds like it came from some 1950s Sci-Fi novel. Anywho, multi-dimensional arrays
are simply arrays within arrays. You remember eariler how I was putting variables into arrays? Well now I'm
stuffing arrays into arrays. For example, let's say I run an on-line bookstore and I sell novels, kid's books,
and magazines, and I put the names of those into arrays. In code, it'd look like:
<?php
$arrayNovels = array("Andromeda Strain", "Rainbow Six", "Lord of the Rings");
$arrayKidBooks = array("Jack and Jill", "Clifford the Big Red Dog", "How Stuff Works");
$arrayMagazines = array("Motorcycle World", "Guitar One", "Car and Driver");
?>
Now this is fairly condensed, but I can stuff all three arrays into an array called
$arrayInventory. Using what I've already talked about, this is how it's done:
<?php
$arrayNovels = array("Andromeda Strain", "Rainbow Six", "Lord of the Rings");
$arrayKidBooks = array("Jack and Jill", "Clifford the Big Red Dog", "How Stuff Works");
$arrayMagazines = array("Motorcycle World", "Guitar One", "Car and Driver");
$arrayInventory = array();
$arrayInventory["arrayNovels"] = $arrayNovels; // this is the same as index 0
$arrayInventory["arrayKidBooks"] = $arrayKidBooks; // this is the same as index 1
$arrayInventory["arrayMagazines"] = $arrayMagazines; // this is the same as index 2
?>


