Create a tree view using php

I have this function that generates menu my problem is I have a specific design if there is a parent and when there is none.

Here is the sample array that I am generating:

{“ITEMS”:{“1”:{“MENU_ID”:”1″,”0″:”1″,”MENU”:”Settings”,”1″:”Settings”,”PARENT_MENU”:”0″,”2″:”0″,”IS_LINK”:0,”3″:0,”MENU_LINK”:null,”4″:null},”5″:{“MENU_ID”:”5″,”0″:”5″,”MENU”:”Views”,”1″:”Views”,”PARENT_MENU”:”0″,”2″:”0″,”IS_LINK”:1,”3″:1,”MENU_LINK”:”page.php?module=09&menu=0d”,”4″:”page.php?module=09&menu=0d”},”6″:{“MENU_ID”:”6″,”0″:”6″,”MENU”:”Plugins”,”1″:”Plugins”,”PARENT_MENU”:”0″,”2″:”0″,”IS_LINK”:1,”3″:1,”MENU_LINK”:”page.php?module=09&menu=0e”,”4″:”page.php?module=09&menu=0e”},”2″:{“MENU_ID”:”2″,”0″:”2″,”MENU”:”Modules”,”1″:”Modules”,”PARENT_MENU”:”1″,”2″:”1″,”IS_LINK”:1,”3″:1,”MENU_LINK”:”page.php?module=09&menu=0a”,”4″:”page.php?module=09&menu=0a”},”3″:{“MENU_ID”:”3″,”0″:”3″,”MENU”:”Models”,”1″:”Models”,”PARENT_MENU”:”1″,”2″:”1″,”IS_LINK”:1,”3″:1,”MENU_LINK”:”page.php?module=09&menu=0b”,”4″:”page.php?module=09&menu=0b”},”4″:{“MENU_ID”:”4″,”0″:”4″,”MENU”:”Menu Items”,”1″:”Menu Items”,”PARENT_MENU”:”3″,”2″:”3″,”IS_LINK”:1,”3″:1,”MENU_LINK”:”page.php?module=09&menu=0c”,”4″:”page.php?module=09&menu=0c”}},”PARENTS”:{“0”:[“1″,”5″,”6″],”1”:[“2″,”3″],”3”:[“4”]}}

The code below is my function that generates the html design of the menu.

I am having a hard time checking if the menu has a parent or not kindly see (if(in_array(, $menu[‘PARENTS’][0])){). What do I need to change in my code to che


public function generate_menu($parent, $menu){
        if ($this->databaseConnection()) {
            $menu_item = '';
            if (isset($menu['PARENTS'][$parent])) {
                foreach ($menu['PARENTS'][$parent] as $item_id) {
                    if (!isset($menu['PARENTS'][$item_id])) {
                       # if($menu['PARENTS'][0] != $menu['PARENTS'][$item_id]){
                        

                        // Here is my problem
                        if(in_array(, $menu['PARENTS'][0])){
                            //Without parent menu
                            $menu_item .= '<li class="nav-item dropdown"><a href="'. $menu['ITEMS'][$item_id]['MENU_LINK'] .'" class="nav-link">'. $menu['ITEMS'][$item_id]['MENU'] .'</a></li>';
                        }
                        else{
                            // With Parent menu
                            $menu_item .= '<a href="'. $menu['ITEMS'][$item_id]['MENU_LINK'] .'" class="dropdown-item"">'. $menu['ITEMS'][$item_id]['MENU'] .'</a>';
                        }


                    }
                    
                    if (isset($menu['PARENTS'][$item_id])) {
                        $menu_item .= '<li class="nav-item dropdown">
                                            <a class="nav-link dropdown-toggle arrow-none" href="javascript: void(0);" id="topnav-user-access" role="button">
                                                <span key="t-user-access">'. $menu['ITEMS'][$item_id]['MENU'] .'</span> <div class="arrow-down"></div>
                                            </a>';
                        $menu_item .= '<div class="dropdown-menu" aria-labelledby="topnav-user-access">';
                        $menu_item .= $this->generate_menu($item_id, $menu);
                        $menu_item .= '</div></li>';
                    }
                }
            }

            return $menu_item;
        }
    }