Php Array Multidimensional


 

Php Array Multidimensional

In this PHP Tutorial section we will learn how to make the multidimensional array in PHP.

In this PHP Tutorial section we will learn how to make the multidimensional array in PHP.

  • In the Multidimensional array, elements of the array are itself array
  • Multidimensional array can be two dimensional or multidimensional array


PHP Multidimensional Array Example

<?php
    $nature
=array(
    array
("cat","bear","mammoth"),
    array
("rose","lily","marigoid"),
    array
("parrot","cock","sparrow")
       );
    echo
"<br><u>all array elements are</u><br>";
    print_r($nature);
    echo
"<br><u>array1 elements are</u><br>";
    print_r($nature[0]);
    echo
"<br><u>array2 elements are</u><br>";
    print_r($nature[1]);
    echo
"<br><u>array22 elements are</u><br>";
    print_r($nature[2][2]);
?>

Output

all array elements are
Array ( [0] => Array ( [0] => cat [1] => bear [2] => mammoth ) [1] => Array ( [0] => rose [1] => lily [2] => marigoid ) [2] => Array ( [0] => parrot [1] => cock [2] => sparrow ) )
array1 elements are
Array ( [0] => cat [1] => bear [2] => mammoth )
array2 elements are
Array ( [0] => rose [1] => lily [2] => marigoid )
array22 elements are
sparrow

Ads