PHP Tutorial
PHP multidimensional array is also known as array of arrays.
A multi-dimensional array each element in the main array can also be an array.
$variable = array (
array("valueAsIndex",value1,value1),
array("valueAsIndex",value1,value1),
array("valueAsIndex",value1,value1),
array("valueAsIndex",value1,value1)
);
Let's see a simple example of PHP multidimensional array to display following tabular data. we are displaying 3 rows and 3 columns.
Id | Name | Salary |
---|---|---|
1 | will | 1234 |
2 | sam | 5678 |
3 | rani | 9012 |
Let's put these syntax into real use.
Following is the example showing how to create and access multidimensional arrays.
<?php
$emp = array
(
array(1,"will",1234),
array(2,"sam",5678),
array(3,"rani",9012)
);
for ($row = 0; $row < 3; $row++) {
for ($col = 0; $col < 3; $col++) {
echo $emp[$row][$col]." ";
}
echo "<br />";
}
?>
This will produce the following result −
1 will 1234
2 sam 5678
3 rani 9012