home | O'Reilly's CD bookshelfs | FreeBSD | Linux | Cisco | Cisco Exam  


Programming PHPProgramming PHPSearch this book

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]


Library Navigation Links

Copyright © 2003 O'Reilly & Associates. All rights reserved.