What are multidimensional associative arrays in PHP? How to retrieve values from them?


Multidimensional arrays store multiple arrays whereas associative arrays store key-value pairs as data. Grouped relation between data can be stored in multidimensional associative arrays.

Example

 Live Demo

<?php
$my_arr = array();
$my_arr['Employee'] = array(
   "Name" => "Joe",
   "Age" => "20",
   "Birth_date" => "2000",
   "Job_details" => array(
      "Position" => "Manager",
      "Salary" => "Lakhs"
   )
);
print_r($my_arr['Employee']['Name']);
echo "
"; echo $my_arr['Employee']['Age']; ?>

Output

Joe 20

An array is defined that contains various attributes of an employee. The employee array is accessed based on the index names and the data is displayed on the console.

Updated on: 02-Jul-2020

918 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements