Specifications
FIGURE 3.4
This three-dimensional array allows us to divide products into categories.
From the code that defines this array, you can see that a three-dimensional array is an array
containing arrays of arrays.
$categories = array( array ( array( “TIR”, “Tires”, 100 ),
array( “OIL”, “Oil”, 10 ),
array( “SPK”, “Spark Plugs”, 4 )
),
array ( array( “TIR”, “Tires”, 100 ),
array( “OIL”, “Oil”, 10 ),
array( “SPK”, “Spark Plugs”, 4 )
),
array ( array( “TIR”, “Tires”, 100 ),
array( “OIL”, “Oil”, 10 ),
array( “SPK”, “Spark Plugs”, 4 )
)
);
Because this array has only numeric indices, we can use nested for loops to display its con-
tents.
for ( $layer = 0; $layer < 3; $layer++ )
{
echo “Layer $layer<BR>”;
for ( $row = 0; $row < 3; $row++ )
{
for ( $column = 0; $column < 3; $column++ )
{
Using PHP
P
ART I
78
Code Description
Truck Parts
Price
TYR Tyres 100
OIL Oil 10
SPK Spark Plugs 4
Code Description
Van Parts
Price
TYR Tyres 100
OIL Oil 10
SPK Spark Plugs 4
product attribute
Code Description
Car Parts
Price
CAR_TIR Tires 100
CAR_OIL Oil 10
CAR_SPK Spark Plugs 4
product category
product
05 7842 CH03 3/6/01 3:42 PM Page 78