Multi-Dimensional Arrays
Let's create a two-dimensional array that contains 3 arrays:
$people = array(
'online'=>array('David', 'Amy'),
'offline'=>array('John', 'Rob', 'Jack'),
'away'=>array('Arthur', 'Daniel')
);
'online'=>array('David', 'Amy'),
'offline'=>array('John', 'Rob', 'Jack'),
'away'=>array('Arthur', 'Daniel')
);
Now the two-dimensional $people array contains 3 arrays, and it has two indices: row and column.
To access the elements of the $people array, we must point to the two indices.
echo $people['online'][0]; //Outputs "David"
echo $people['away'][1]; //Outputs "Daniel"
echo $people['away'][1]; //Outputs "Daniel"
The arrays in the multi-dimensional array can be both numeric and associative.
No comments:
Post a Comment