PHP PHP Multidimensional Array

PHP Multidimensional Array

Each element in the main array can also be an array, and each element in sub-array can be array, and so on. is called multidimensional array.
Values in the multidimensional array are accessed using multiple indexes.
Generally 2 or 3 dimensional array is used. it is difficult to manage more dimensional array.


Consider example of Marks in previous tutorial. if we have to store and access Marks of all student in the class.
Then we use multidimensional array as follows.

    $marks = array(
              "Raju" => array(
                          "Maths"=>"35", "Science"=>"36", "English"=>"35"),
              "Shyam" => array(
                          "Maths"=>"85", "Science"=>"89", "English"=>"78"),
              "Baburav" => array(
                          "Maths"=>"05", "Science"=>"01", "English"=>"07"),
    echo "Raju Obtained Marks in Maths = ".$marks['Raju']['Maths'];
    echo "<br />";
    echo "Shyam Obtained Marks in Science = ".$marks['Shyam']['Science'];
    echo "<br />";
    echo "Baburav Obtained Marks in English = ".$marks['Baburav']['English'];

Raju Obtained Marks in Maths = 35
Shyam Obtained Marks in Science = 89
Baburav Obtained Marks in English = 07

Share This Page on:

Ask Question