Advertisement
Google Ad Slot: content-top
PHP Multidimensional Arrays
A multidimensional array in PHP is an array containing one or more arrays. Multidimensional arrays allow you to create complex data structures, such as matrices, tables, or any nested structure. PHP supports both indexed and associative arrays as sub-arrays in a multidimensional array.
Note
The dimension of an array indicates the number of indices required to access a specific element in that array.
- You need 2 indices to access an element of two-dimensional array
- You need 3 indices to access an element of three-dimensional array
PHP Multidimensional Array Example
Let's see a simple example of PHP multidimensional array to display following tabular data. In this example, we are displaying 3 rows and 2 columns.
Name |
Age |
|---|---|
John |
30 |
Alice |
25 |
Bob |
35 |
To get access to the elements of the above table we must point to the two indices (row and column):