PHP Multidimensional Array PHP

PHP Multidimensional Array  

PHP Multidimensional Array

PHP Multidimensional Array

PHP multidimensional array is also known as array of arrays. It allows you to store tabular data in an array. PHP multidimensional array can be represented in the form of matrix which is represented by row * column.

Definition

  1. $emp = array  
  2.   (  
  3.   array(1,"sonoo",400000),  
  4.   array(2,"john",500000),  
  5.   array(3,"rahul",300000)  
  6.   );  

PHP Multidimensional Array Example

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

Id Name Salary
1 sonoo 400000
2 john 500000
3 rahul 300000

File: multiarray.php

  1. <?php    
  2. $emp = array  
  3.   (  
  4.   array(1,"sonoo",400000),  
  5.   array(2,"john",500000),  
  6.   array(3,"rahul",300000)  
  7.   );  
  8.   
  9. for ($row = 0; $row < 3; $row++) {  
  10.   for ($col = 0; $col < 3; $col++) {  
  11.     echo $emp[$row][$col]."  ";  
  12.   }  
  13.   echo "<br/>";  
  14. }  
  15. ?>    

Output:

1 sonoo 400000
2 john 500000
3 rahul 300000 

Download free E-book of PHP


#askProgrammers
Learn Programming for Free


Join Programmers Community on Telegram


Talk with Experienced Programmers


Just drop a message, we will solve your queries