Multi-dimensional arrays is a type of arrays which stores an another array at each index instead of single element. In simple words, multi-dimensional arrays as array of arrays, every element in this array can be an array and they can also hold other sub-arrays within. Arrays or sub-arrays in multidimensional arrays can be accessed using multiple dimensions.
Dimensions of multidimensional array indicates the number of indices needed to select an element. For a two dimensional array two indices to select an element.
Associative array: Al associative array is similar to indexed array but instead of linear storage (indexed storage), every value can be assigned with a user-defined key of string type. Example :-
Output :-
Array
(
[new1] => manishkumar
[new2] => amitkumar
[new3] => 19
[new5] => 90
[new6] => 1
[new7] =>
[new8] =>
)
19
90
1
Multidimensional Array : It is the form of multidimensional array. Initialization in Three-Dimensional array is same as that of Two-dimensional arrays. The difference is as the number of dimension increases so the number of nested braces will also increase.
Accessing multidimensional array elements: There are mainly two ways to access multidimensional array elements in PHP.
- Elements can be accessed using dimensions as array_name[‘first dimension’][‘second dimension’].
- Elements can be accessed using for loop.
- Elements can be accessed using for each loop.
Output:-
1 Mukesh Manager Digital Marketing 50000
2 Nitesh Asst Manager Software Develoer 35000
3 Nilotma Senior Manager Tech team 76000
4 ritesh Junior Manager SEO 15000
5 Rakesh Area Manager Sales Marketing 40000
| Emp Id | Emp Name | Emp Designation | Emp Department | Emp Salary |
|---|---|---|---|---|
| 1 | Mukesh | Manager | Digital Marketing | 50000 |
| 2 | Nitesh | Asst Manager | Software Develoer | 35000 |
| 3 | Nilotma | Senior Manager | Tech team | 76000 |
| 4 | ritesh | Junior Manager | SEO | 15000 |
| 5 | Rakesh | Area Manager | Sales Marketing | 40000 |
;
| Emp Id | Emp Name | Emp Designation | Emp Department | Emp Salary |
|---|---|---|---|---|
| 1 | Manish | Manager | Area Manager | 73000 |
| 2 | Kumar | Senior Manager | Tech team | 65000 |
| 3 | Kumari Puja | Junior Manager | Technical deptt | 66000 |
| 4 | Nillu Kumari | Asst Manager | Software Devloper | 35000 |
| 5 | Sita prasad | Software Develoer | Sales Area Manager | 48000 |
Copy code and use it by yourself on your editor for better understanding of Output.
Thank You !!