我在函数中添加了此代码。php检索菜单并将其转换为可读的数组,但它不起作用,请给出此警告。警告:为foreach()inC:\\xampp\\htdocs\\Upwork\\wp content\\themes\\truckloanhub\\functions提供的参数无效。phpon线路117
警告:为foreach()inC:\\xampp\\htdocs\\Upwork\\wp content\\themes\\truckloanhub\\functions提供的参数无效。phpon线路127
function wp_get_menu_array($current_menu) {
$array_menu = wp_get_nav_menu_items($current_menu);
$menu = array();
foreach ($array_menu as $m) {
if (empty($m->menu_item_parent)) {
$menu[$m->ID] = array();
$menu[$m->ID][\'ID\'] = $m->ID;
$menu[$m->ID][\'title\'] = $m->title;
$menu[$m->ID][\'url\'] = $m->url;
$menu[$m->ID][\'children\'] = array();
}
}
$submenu = array();
foreach ($array_menu as $m) {
if ($m->menu_item_parent) {
$submenu[$m->ID] = array();
$submenu[$m->ID][\'ID\'] = $m->ID;
$submenu[$m->ID][\'title\'] = $m->title;
$submenu[$m->ID][\'url\'] = $m->url;
$menu[$m->menu_item_parent][\'children\'][$m->ID] = $submenu[$m->ID];
}
}
return $menu;
}