类似my previous question, 我想打印仪表板中所有子菜单项的列表,如下所示:
- Updates > 更新core。phpLibrary > 上载phpAdd New > 新媒体。php等
这就是我目前所拥有的:
global $submenu;
foreach ( $submenu as $group => $item ) {
echo \'<pre>\'; print_r( $item ); echo \'</pre>\';
}
// echo \'<pre>\'; print_r( $submenu ); echo \'</pre>\';
输出
Array (
[0] => Array (
[0] => Home
[1] => read
[2] => index.php
)
[10] => Array (
[0] => Updates 4
[1] => update_core
[2] => update-core.php
)
)
Array (
[5] => Array (
[0] => Library
[1] => upload_files
[2] => upload.php
)
[10] => Array (
[0] => Add New
[1] => upload_files
[2] => media-new.php
)
)
AND SO ON...
我知道这是一个玩弄
foreach
使用正确的索引,如
my previous question, 但我有麻烦了。非常感谢您的帮助和指导。
最合适的回答,由SO网友:Nate Allen 整理而成
如果您希望将它们放在无序列表中:
echo "<ul>\\r\\n";
foreach ( $submenu as $group => $item ) {
foreach ( $submenu[$group] as $key => $value ) {
echo "<li>" . $submenu[$group][$key][0] . " > " . $submenu[$group][$key][2] . "</li>\\r\\n";
}
}
echo "</ul>";
这将导致:
<ul>
<li>Home > index.php</li>
<li>Updates > update-core.php</li>
<li>Library > upload.php</li>
<li>Add New > media-new.php</li>
</ul>