Multidimensional array stores one or more than one array and hence is also called Array of Arrays, There can be array inside an array and so on. it means two dimensional, three dimensional array and so on. There is no limit in creating multidimensional array but becomes hard to manage as dimension increases.

Syntax

Two dimensional array syntax

$arr = array(
         array();
         array();
         array();
         array();

      );

Three dimensional array syntax

$arr = array(
         array(
		 array();
                 array();
          );
         array(
		 array();
 		array();

          );
	  array(
		 array();
		 array();

          );


      );

Two dimensional array example

Two dimensional array is represents data in row and column format i.e. tabular format.

<?php
  $student = array  
  (  
  array(1,"Vasu","Maths"),  
  array(2,"Rahul","Bio"),  
  array(3,"Rohit","Commerce"),
  array(3,"Vijay","Maths")    
  );  
?>

Above example creates 4 rows and 3 columns.

Accessing two dimensional array example

<?php
for ($row = 0; $row < 4; $row++) {  
  for ($col = 0; $col < 4; $col++) {  
    echo $student[$row][$col]."  ";  
  }  
  echo "<br/>";  
}  
?>

Three dimensional array

Same as two dimensional array but one more dimension is added

<?php
$arr = array(
    array(
        array("Vasu", "Bio"),
        array("language", "PHP"),
    ),
    array(
        array("Rohit", "Maths"),
        array("language", "PHP & JS"),
    ),
);
?>