How can PHP arrays be effectively used to organize and display category structures in a forum setting?

To effectively organize and display category structures in a forum setting using PHP arrays, you can create a multidimensional array where each category can have subcategories nested within it. This allows for a hierarchical structure that can be easily traversed and displayed in a forum layout.

// Sample multidimensional array representing forum categories and subcategories
$forumCategories = [
    'General' => [
        'Introductions',
        'Announcements',
        'Feedback',
    ],
    'Programming' => [
        'PHP',
        'JavaScript',
        'Python',
    ],
    'Design' => [
        'UI/UX',
        'Graphic Design',
    ],
];

// Loop through the categories and subcategories to display them in a forum layout
foreach ($forumCategories as $category => $subcategories) {
    echo "<h2>$category</h2>";
    echo "<ul>";
    foreach ($subcategories as $subcategory) {
        echo "<li>$subcategory</li>";
    }
    echo "</ul>";
}