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");
?>
$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
?>
<?php
$nSizeInv = count($ArrayInventory);
for($indexInv=0; $indexInv < $nSizeInv; $indexInv++)
{
if($indexInv==0) // remember that index 0 is the array for novels
{
$arrayNovels = $ArrayInventory[$index];
$nSizeNovels = count($arrayNovels);
for($indexNov=0; $indexNov < $nSizeNovels; $indexNov++)
{
$sNovel = $arrayNovels[$indexNov];
print "Novel: $sNovel";
}
}
if($indexInv==1) // remember that index 1 is the array for kid's books
{
$arrayKidsBooks = $ArrayInventory[$index];
$nSizeKbooks = count($arrayKidsBooks);
for($indexKbook=0; $indexKbook < $nSizeKbooks; $indexKbook++)
{
$sKidsBook = $arrayKidsBooks[$indexKbook];
print "Kids book: $sKidsbook";
}
}
if($indexInv==2) // remember that index 2 is the array for magazines
{
$arrayMagazines = $ArrayInventory[$index];
$nSizeMags = count($arrayMagazines);
for($indexMags=0; $indexMags < $nSizeMags; $indexMags++)
{
$sMagazine = $arrayMagazines[$indexMags];
print "Magazine: $sMagazine";
}
}
}
?>
the address above if you have a specific question about arrays or PHP in general. Thanks, and may the
code be with you.