5.4 Multidimensional Arrays


The values in an array can themselves be arrays. This lets you easily create multidimensional arrays:

$row_0 = array(1, 2, 3); $row_1 = array(4, 5, 6); $row_2 = array(7, 8, 9); $multi = array($row_0, $row_1, $row_2);

You can refer to elements of multidimensional arrays by appending more []s:

$value = $multi[2][0];                 // row 2, column 0. $value = 7

To interpolate a lookup of a multidimensional array, you must enclose the entire array lookup in curly braces:

echo("The value at row 2, column 0 is {$multi[2][0]}\n");

Failing to use the curly braces results in output like this:

The value at row 2, column 0 is Array[0]


Programming PHP
Programming PHP
ISBN: 1565926102
EAN: 2147483647
Year: 2007
Pages: 168

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net