src/Collection/LeanMenu.php
public function get_sub_menu_items( $menu_items, $parent_id ) {
		$items = [];

		foreach ( $menu_items as $menu_item ) {
			if ( intval( $parent_id ) === intval( $menu_item->menu_item_parent ) ) {
				$items[] = [
					'title' => $menu_item->title,
					'link' => str_replace( site_url(), '', $menu_item->url ),
					'items' => self::get_sub_menu_items( $menu_items, $menu_item->ID ),
				];
			}
		}

		return $items;
	}
public function get_sub_menu_items( $menu_items, $parent_id ) {
		$items = [];

		foreach ( $menu_items as $menu_item ) {
			if ( intval( $parent_id ) === intval( $menu_item->menu_item_parent ) ) {
				$items[] = [
					'title' => $menu_item->title,
					'link' => str_replace( site_url(), '', $menu_item->url ),
					'items' => self::get_sub_menu_items( $menu_items, $menu_item->ID ),
				];
			}
		}

		return $items;
	}
public function get_sub_menu_items ( $ menu_items , $ parent_id ) { $ items = [ ] ; foreach ( $ menu_items as $ menu_item ) { if ( intval ( $ parent_id ) === intval ( $ menu_item -> menu_item_parent ) ) { $ items [ ] = [ 'title' => $ menu_item -> title , 'link' => str_replace ( site_url ( ) , '' , $ menu_item -> url ) , 'items' => self :: get_sub_menu_items ( $ menu_items , $ menu_item -> ID ) , ] ; } } return $ items ; }
Recursively get all sub menu items.

@param array $menu_items All menu items.
@param int   $parent_id  The parent menu id.
@return array
Recursively get all sub menu items .