PHP Two Dimensional Array

Techno PHP

Two-dimensional arrays have rows and columns .
The Two-dimensional array is a list of one-dimensional arrays. To declare two-dimensional integer array of size [x][y].


Example

<?php 
$x=array('Vishal'=>array('20','1997','MCA'),
         'Manish'=>array('25','1992','M-Tech'));
		 echo $x['Vishal'][2];
		 
?>
Run

In above example we have an array in which vishal's age 20 ,year 1997 and qualification MCA same like for Manish's age 25,year 1992, qualification M-tech .
We declared a variable $x for the array .After that if we have need to find out What is qualification of Vishal then we will use the Two dimensional array as above example .

[Vishal] [2] . We have wrote a instruction that fetch the vishal qualification that is stored index number 2 .
[2] is a index number of array . .

Example

<?php 
In other example we will find the Manish Class .
$x=array('Vishal'=>array('age'=>'20','age'=>'1997','class'=>'MCA'),
         'Manish'=>array('age'=>'20','age'=>'1992','class'=>'M-Tech'));
		 echo $x['Manish']['class'];
?>
Run
Find out the class of Manish using Two dimensional Array.

Related