PHP Multidimensional Arrays
Multidimensional arrays in PHP are arrays that contain other arrays as elements.
Example of PHP Multidimensional Arrays
<?php
$person = array(
"name" => "John",
"age" => 30,
"address" => array(
"street" => "123 Main St",
"city" => "New York",
"state" => "NY"
)
);
echo $person['name'] . "\n";
// Outputs: John
echo $person['age'] . "\n";
// Outputs: 30
echo $person['address']['street'] . "\n";
// Outputs: 123 Main St
echo $person['address']['city'] . "\n";
// Outputs: New York
echo $person['address']['state'] . "\n";
// Outputs: NY
?>
Output:
John
30
123 Main St
New York
NY
Explanation: This example demonstrates the use of multidimensional arrays in PHP. The array is defined with three elements, and the third element is another array that contains three elements.