close[x]


PHP

PHP-Home PHP-Environment Setup PHP-Syntax PHP-Run PHP in XAMPP PHP-Variable PHP-Comment PHP-Datatype PHP-String PHP-Operators PHP-Decision PHP-loop PHP-Get/Post PHP-Do While loop PHP-While loop PHP-For loop PHP-Foreach loop PHP-Array PHP-Multidimensional Arrays PHP-Associative Arrays PHP-Indexed Arrays PHP-Function PHP-Cookies. PHP-Session PHP-File upload PHP-Email PHP-Data & Time PHP-Include & Require PHP-Error PHP-File I/O PHP-Read File PHP-Write File PHP-Append & Delete File PHP-Filter PHP-Form Validation PHP-MySQl PHP-XML PHP-AJAX



learncodehere.com




PHP - Multidimensional Array

PHP multidimensional array is also known as array of arrays.

A multi-dimensional array each element in the main array can also be an array.

Syntax : Create Multidimensional Array


 $variable = array (
  array("valueAsIndex",value1,value1),
  array("valueAsIndex",value1,value1),
  array("valueAsIndex",value1,value1),
  array("valueAsIndex",value1,value1)
);

Let's see a simple example of PHP multidimensional array to display following tabular data. we are displaying 3 rows and 3 columns.

Id Name Salary
1 will 1234
2 sam 5678
3 rani 9012


Let's put these syntax into real use.

Following is the example showing how to create and access multidimensional arrays.

Example : foreach Loop


<?php 
$emp = array  
  (  
  array(1,"will",1234),  
  array(2,"sam",5678),  
  array(3,"rani",9012)  
  );  
for ($row = 0; $row < 3; $row++) {  
  for ($col = 0; $col < 3; $col++) {  
    echo $emp[$row][$col]."  ";  
  }  
  echo "<br />";  
}  
?>

This will produce the following result −

Result

1 will 1234

2 sam 5678

3 rani 9012