How can the PHP code provided be modified to output the customer address data in a vertical format rather than a horizontal one?
To output the customer address data in a vertical format rather than a horizontal one, you can iterate over the address array and echo each element on a new line. This can be achieved by using a foreach loop to iterate over the address array and echo each key-value pair on a separate line.
<?php
$customer = [
'name' => 'John Doe',
'address' => [
'street' => '123 Main Street',
'city' => 'Anytown',
'state' => 'CA',
'zip' => '12345'
]
];
echo "Customer Name: " . $customer['name'] . "<br>";
echo "Customer Address:<br>";
foreach ($customer['address'] as $key => $value) {
echo $key . ": " . $value . "<br>";
}
?>
Related Questions
- What are some recommended online resources for beginners to learn PHP effectively?
- When cloning data in PHP, is it better to copy all data first and then make changes, or to make changes during the cloning process?
- What are some best practices for structuring MySQL tables to manage user and group notifications in a PHP application?