 <p>Use recursive function</p> <pre><code>$menusList = array(); function dynamic_menus($menus) { foreach($menus as $index =&gt; $subMenu) { menusList[$index] = is_array($subMenu) ? dynamic_menus($subMenu) : $subMenu; } return menusList; } </code></pre>