Page 156 - Open Soource Technologies 304.indd
P. 156
Web Technologies-I
Notes Multidimensional arrays can be described as “arrays of arrays”. For example,
a bidimensional array can be imagined as a bidimensional table made of
elements, all of them of a same uniform data type.
7.1.2 Three-dimensional Arrays
A three-dimensional array has height, width, and depth. If you are comfortable thinking of a
two-dimensional array as a table with rows and columns imagine a pile or deck of those tables.
Each element will be referenced by its layer, row, and column.
If Bob divided his products into categories, we could use a three-dimensional array to store
them. Figure 7.1 shows Bob’s products in a three-dimensional array.
Figure 7.1: 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( ‘CAR_TIR’, ‘Tires’, 100 ),
array( ‘CAR_OIL’, ‘Oil’, 10 ),
array( ‘CAR_SPK’, ‘Spark Plugs’, 4 )
),
array ( array( ‘VAN_TIR’, ‘Tires’, 120 ),
array( ‘VAN_OIL’, ‘Oil’, 12 ),
array( ‘VAN_SPK’, ‘Spark Plugs’, 5 )
),
array ( array( ‘TRK_TIR’, ‘Tires’, 150 ),
array( ‘TRK_OIL’, ‘Oil’, 15 ),
150 LOVELY PROFESSIONAL UNIVERSITY