PHP - Accessing Elements of Multidimensional Arrays

Introduction

Using the square bracket syntax, you can access any element within a multidimensional array.

Here are some examples (these work on the $myBooks array just shown):

Demo

<?php
         $myBooks = array(
           array(
            "title"=> "Java",
            "author"=> "John A",
            "pubYear"=>  2018
        ),/*from  w w w.j a  v a  2s .c  om*/
           array(
            "title"=> "Database",
            "author"=> "Franz B",
            "pubYear"=>  2017
        ),
           array(
            "title"=> "Json",
            "author"=> "Oracle",
            "pubYear"=>  2018
        ),
           array(
            "title"=> "MySQL",
            "author"=> "Charles D",
            "pubYear"=>  1859
        ),
      );
print_r($myBooks[1]);
echo"\n". $myBooks[1]["title"]."\n";
echo $myBooks[3]["pubYear"]."\n";
?>

Result

Related Topic