PHP Multidimensional Arrays

An array with two or more arrays are called multi-dimensional arrays in PHP. So in this tutorial we will understand about the multi-dimensional array in PHP.

What is Multi-dimensional array in PHP

It is not necessary that all the arrays have one key values but one key of array  may have other arrays. So a multi-dimensional array could be of 1 level, 2 level, 3 level, 4 level or more. So those arrays are called multi-dimensional arrays in PHP.

Two-dimensional array in PHP

Let us understand two-dimensional array with an example. Suppose you are a teacher and you want to prepare an exam record of class 10 with student name, roll number and marks as shown in the following table:

Student Name Roll Number Marks
Andy 101 50
Ian 102 75
david 103 68

If we need to maintain only the student name then this can be done with one-dimensional array but in our case, we need to keep a complete record of each student. So we need a multi-dimensional array (two dimensional array in our case here) this purpose.

So a two-dimensional array is a combination of multiple arrays. you can understand this with the following example:

We hope you understand the concept behind the multi-dimensional arrays.


Leave a Reply

Your email address will not be published.