How can multidimensional arrays be efficiently utilized to store and display data in PHP?
Multidimensional arrays can efficiently store and display data in PHP by organizing information in a structured way. This can be particularly useful for handling complex data sets, such as a list of items with multiple attributes. By using nested arrays, you can easily access and manipulate the data in a logical manner.
// Example of utilizing a multidimensional array to store and display data
$data = array(
array("name" => "John", "age" => 25, "city" => "New York"),
array("name" => "Jane", "age" => 30, "city" => "Los Angeles"),
array("name" => "Bob", "age" => 22, "city" => "Chicago")
);
// Displaying the data
foreach ($data as $person) {
echo "Name: " . $person['name'] . ", Age: " . $person['age'] . ", City: " . $person['city'] . "<br>";
}