PHP Multidimensional Array

The array of arrays in PHP is  known as a multidimensional array. The array’s elements can all be arrays, and they can also contain additional sub-arrays. It enables the storage of tabular data in an array. PHP multidimensional arrays can be expressed as a matrix, with row * column.

PHP Multidimensional Array Definition

$MainArray=array(
          $array1=array(
                //data for array one               
                   )                              
          $array2=array(
                //data for array 2               
                   )
             // you can as as many sub arrays as you want

)
<h2>Example of Multidimensional Array</h2>
      <?php
         $marks = array( 
            "Hadi" => array (
               "physics" => 45,
               "maths" => 35,	
               "chemistry" => 25
            ),
            
            "Sohaib" => array (
               "physics" => 39,
               "maths" => 36,
               "chemistry" => 41
            ),
            
            "Sidra" => array (
               "physics" => 41,
               "maths" => 42,
               "chemistry" => 29
            )
         );
         
         /* Accessing multi-dimensional array values */
         echo "Marks for Hadi in physics : " ;
         echo $marks['Hadi']['physics'] . "<br />"; 
         
         echo "Marks for Sohaib in maths : ";
         echo $marks['Sohaib']['maths'] . "<br />"; 
         
         echo "Marks for Sidra in chemistry : " ;
         echo $marks['Sidra']['chemistry'] . "<br />"; 
      ?>