PHP | Multidimensional arrays

Pascal - Multi-dimensional Array

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 IdEmp NameEmp DesignationEmp DepartmentEmp Salary
1MukeshManagerDigital Marketing50000
2NiteshAsst ManagerSoftware Develoer35000
3NilotmaSenior ManagerTech team76000
4riteshJunior ManagerSEO15000
5RakeshArea ManagerSales Marketing40000

;

Emp IdEmp NameEmp DesignationEmp DepartmentEmp Salary
1ManishManagerArea Manager73000
2KumarSenior ManagerTech team65000
3Kumari PujaJunior ManagerTechnical deptt66000
4Nillu KumariAsst ManagerSoftware Devloper35000
5Sita prasadSoftware DeveloerSales Area Manager48000

Copy code and use it by yourself on your editor for better understanding of Output.

Thank You !!