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 the best practices for handling text length in column headers in responsive tables using Bootstrap and PHP?
- What steps can be taken to troubleshoot and debug cURL requests in PHP when encountering authorization issues like "Unauthorized"?
- What are the best practices for handling incomplete data entries in MySQL tables when querying them in PHP?