PHP - Array Multidimensional Arrays

Introduction

The following script creates a simple two-dimensional array called $myBooks, then displays its contents using print_r().

Demo

<?php
         $myBooks = array(
           array(
            "title"=> "Java",
            "author"=> "John A",
            "pubYear"=>  2018
        ),//from   w  w  w  .ja v a2 s .c  o  m
           array(
            "title"=> "Database",
            "author"=> "Franz B",
            "pubYear"=>  2017
        ),
           array(
            "title"=> "Json",
            "author"=> "J. R. R. C",
            "pubYear"=>  2018
        ),
           array(
            "title"=> "MySQL",
            "author"=> "Charles D",
            "pubYear"=>  1859
        ),
      );

         print_r ($myBooks);
?>

Result

Here, this script creates an indexed array, $myBooks, that contains four elements with the keys 0, 1, 2, and 3.

Each element is, in turn, an associative array that contains three elements with keys of "title", "author", and "pubYear".

Related Topics