Follow The New Tutorial updates on WhatsApp, Telegram or YouTube.

PHP Multidimensional Array

PHP multidimensional array is an array of arrays.

As the name suggests, every element in this array can be an array and they can also hold other sub-arrays within.

A multidimensional array is an array containing one or more arrays. It allows you to store tabular data in an array.

Arrays or sub-arrays in multidimensional arrays can be accessed using multiple dimensions.

PHP Multidimensional Array Example

Let’s see a simple example of PHP multidimensional array to display following tabular data. In this example, we are displaying 5 rows and 3 columns.

IdNameSalary
1Anil400000
2Smith600000
3Peter200000
4John500000
5Rahul300000
PHP Multidimensional Array Example – Data

Example

<?php    
$emp = array  
  (  
  array(1,"Anil",400000),  
  array(2,"Smith",600000),  
  array(3,"Peter",200000), 
  array(4,"John",500000),  
  array(5,"Rahul",300000)  
  );  
  
for ($row = 0; $row < 5; $row++) {  
  for ($col = 0; $col < 3; $col++) {  
    echo $emp[$row][$col]."  ";  
  }  
  echo "<br/>";  
}  
?>    
PHP Multidimensional Array Example – Output