Multidimensional Arrays

In a multidimensional array, each element in the main array can also be an array. And each element in the sub-array can be an array, and so on.

We can define a multidimensional array like below:

[php]
$families = array(
"Griffin"=>array(
"Peter",
"Lois",
"Megan"
),
"Quagmire"=>array (
"Glenn"
),
"Brown"=>array(
"Cleveland",
"Loretta",
"Junior"
)
);
[/php]

That will output:

Array
(
[Griffin] => Array
(
[0] => Peter
[1] => Lois
[2] => Megan
)
[Quagmire] => Array
(
[0] => Glenn
)
[Brown] => Array
(
[0] => Cleveland
[1] => Loretta
[2] => Junior
)
)

You can print out one of the families like below:
[php]
print_r($families[‘Griffin’]);
[/php]

The output will be:

Array
(
[0] => Peter
[1] => Lois
[2] => Megan
)

Below shows you how to print out one of names inside a family:
[php]
print_r($families[‘Griffin’][0]);
[/php]

The output will be:

Peter