protected function reduceItem (MenuItem $item)
    {
        $reduced = ['name' => $item->getTitle()];

        // Has children.
        if (count($item->getChildren()) > 0) {
            $reduced['sub_button'] = [];
            foreach ($item->getChildren() as $childItem) {
                $reduced['sub_button'][] = $this->reduceItem($childItem);
            }
        } // No children.
        else {
            $reduced['type'] = $item->getType();
            $reduced[$item->getType() === MenuItem::URL ? 'url' : 'key'] = $item->getKey();
        }

        return $reduced;
    }
protected function reduceItem (MenuItem $item)
    {
        $reduced = ['name' => $item->getTitle()];

        // Has children.
        if (count($item->getChildren()) > 0) {
            $reduced['sub_button'] = [];
            foreach ($item->getChildren() as $childItem) {
                $reduced['sub_button'][] = $this->reduceItem($childItem);
            }
        } // No children.
        else {
            $reduced['type'] = $item->getType();
            $reduced[$item->getType() === MenuItem::URL ? 'url' : 'key'] = $item->getKey();
        }

        return $reduced;
    }
protected function reduceItem ( MenuItem $ item ) { $ reduced = [ 'name' => $ item -> getTitle ( ) ] ; // Has children. if ( count ( $ item -> getChildren ( ) ) > 0 ) { $ reduced [ 'sub_button' ] = [ ] ; foreach ( $ item -> getChildren ( ) as $ childItem ) { $ reduced [ 'sub_button' ] [ ] = $ this -> reduceItem ( $ childItem ) ; } } // No children. else { $ reduced [ 'type' ] = $ item -> getType ( ) ; $ reduced [ $ item -> getType ( ) === MenuItem :: URL ? 'url' : 'key' ] = $ item -> getKey ( ) ; } return $ reduced ; }
Reduces a menu item, and returns it as an array that can be used in a request to the WeChat API.

@param MenuItem $item

@return array
Reduces a menu item and returns it as an array that can be used in a request to the WeChat API .