PHP Multidimensional Array
ADVERTISEMENTS
What is the multi-dimensional Array in PHP?
Whose array contains inside one or more array, It is called a multidimensional array.
PHP understands multidimensional array 1, 2, 3 ... n levels deep.
Syntax of the multi-dimensional Array
$array = array(
array(
array("data 1", "data 2", .... ,"data n"),
array("data 1", "data 2", .... ,"data n"),
:
:
array("data 1", "data 2", .... ,"data n")
),
array(
array("data 1", "data 2", .... ,"data n"),
array("data 1", "data 2", .... ,"data n"),
:
:
array("data 1", "data 2", .... ,"data n")
),
:
:
array(
array("data 1", "data 2", .... ,"data n"),
array("data 1", "data 2", .... ,"data n"),
:
:
array("data 1", "data 2", .... ,"data n")
)
);
array(
array("data 1", "data 2", .... ,"data n"),
array("data 1", "data 2", .... ,"data n"),
:
:
array("data 1", "data 2", .... ,"data n")
),
array(
array("data 1", "data 2", .... ,"data n"),
array("data 1", "data 2", .... ,"data n"),
:
:
array("data 1", "data 2", .... ,"data n")
),
:
:
array(
array("data 1", "data 2", .... ,"data n"),
array("data 1", "data 2", .... ,"data n"),
:
:
array("data 1", "data 2", .... ,"data n")
)
);
Understand the multidimensional array from this example:
<?php
$var = array(
array("123", "john", "will"),
array("124", "johnny", "doe"),
array("125", "marky", "william"),
array("126", "mark", "zoo")
);
for( $m = 0; $m < 4; $m++ )
{
for( $n = 0; $n < 3; $n++ )
{
echo $var[$m][$n] . "\n";
}
echo "\n";
}
?>
Output:
123
john
will
124
johnny
doe
125
marky
william
126
mark
zoo