How can nested loops be utilized in PHP to display data in a tabular format for a glossary?
To display data in a tabular format for a glossary using nested loops in PHP, you can iterate over an associative array where the keys represent the terms and the values represent the definitions. By using nested loops, you can loop through each key-value pair and display them in a table format with two columns: one for the terms and one for the definitions.
<?php
$glossary = array(
"PHP" => "Hypertext Preprocessor",
"HTML" => "Hypertext Markup Language",
"CSS" => "Cascading Style Sheets"
);
echo "<table border='1'>";
echo "<tr><th>Term</th><th>Definition</th></tr>";
foreach ($glossary as $term => $definition) {
echo "<tr><td>$term</td><td>$definition</td></tr>";
}
echo "</table>";
?>