Multidimensional Arrays

A multi-dimensional array each element in the main array can also be an array. And each element in the sub-array can be an array, and so on. Values in the multi-dimensional array are accessed using multiple index.PHP understands multidimensional arrays that are two, three, four, five, or more levels deep. However, arrays more than three levels deep are hard to manage for most people.

Example :-


1 sonoo 400000
2 john 500000
3 rahul 300000

Two-dimensional Arrays

In PHP, two-dimensional arrays are arrays that contain arrays. You can think of the outer array as containing the rows and the inner arrays as containing the data cells in those rows.

Name Stock Sold
Volvo 22 18
BMW 15 13
Ferrari 5 2
Audi 17 15

We can store the data from the table above in a two-dimensional array, like this:

Now the two-dimensional $cars array contains four arrays, and it has two indices: row and column. To get access to the elements of the $cars array we must point to the two indices (row and column):

Example :-


Volvo: In stock: 22, sold: 18.
BMW: In stock: 15, sold: 13.
Ferrari: In stock: 5, sold: 2.
Audi: In stock: 17, sold: 15.