Share on Google+Share on Google+

Php Array Multidimensional

Advertisement
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

Advertisements

Advertisement

Posted on: October 28, 2009 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Share this Tutorial Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.