PHP Multidimensional Arrays
An array can also contain another array as a value, which in
turn can hold other arrays as well. In such a way we can create two- or
Run example »
// A two-dimensional array:
$cars = array
PHP - Multidimensional Arrays
A multidimensional array is an array containing one or more 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.
In this example we create a multidimensional array, with automatically
assigned ID keys:
$families = array
The array above would look like this if written to the output:
[Griffin] => Array
 => Peter
 => Lois
 => Megan
[Quagmire] => Array
 => Glenn
[Brown] => Array
 => Cleveland
 => Loretta
 => Junior
Lets try displaying a single value from the array above:
echo "Is " . $families['Griffin'] .
" a part of the Griffin family?";
The code above will output:
Is Megan a part of the Griffin family?
Thank You For Helping Us!
Your message has been sent to W3Schools.