Are there any best practices for organizing menu items in a 2-dimensional array in PHP?

When organizing menu items in a 2-dimensional array in PHP, it is best to structure the array in a way that makes it easy to access and display the menu items. One common approach is to use nested arrays where each main menu item is an array containing sub-menu items. This allows for a hierarchical structure that can be easily looped through to generate the menu.

$menuItems = [
    'Home' => [],
    'About' => [],
    'Services' => [
        'Web Development',
        'Graphic Design',
        'Digital Marketing'
    ],
    'Portfolio' => [
        'Web Projects',
        'Design Projects'
    ],
    'Contact' => []
];

// Loop through the menu items
foreach ($menuItems as $menuItem => $subMenuItems) {
    echo $menuItem . PHP_EOL;
    if (!empty($subMenuItems)) {
        foreach ($subMenuItems as $subMenuItem) {
            echo " - " . $subMenuItem . PHP_EOL;
        }
    }
}