在 php 中获取二维数组

fetch 2d array in php

我有一个数组,如下所示:

'Item1' => 
     array (size=5)
     0 => 'under Item1 1' 
     1 => 'under Item1 2' 
     2 => 'under Item1 3' 
     3 => 'under Item1 4'
'Item2' => 
    array (size=4)
    0 => 'under Item2 1' 
    1 => 'under Item2 2'
    2 => 'under Item2 3' 
    3 => 'under Item2 4' 

我想获取该数组并显示一个菜单:所以最终结果必须是这样:

        Item 1
             . under Item1 1
             . under Item1 2
             . under Item1 3
             . under Item1 4
        Item 2
             . under Item2 1
             . under Item2 2
             . under Item2 3
             . under Item2 4

使用数组迭代:

<ul>
    <?php
    foreach ($yourarray as $menu_name => $submenu) {
        echo '<li>'.$menu_name;
        echo '<ul>';

        foreach ($submenu as $submenu_name) {
            echo '<li>'.$submenu_name.'</li>';
        }

        echo '</ul>';
        echo '</li>';
    }
    ?>
</ul>