How can the HTML_Menu package from PEAR be used to create a tree menu in PHP?

To create a tree menu in PHP using the HTML_Menu package from PEAR, you first need to install the package using Composer. Once the package is installed, you can use the HTML_Menu class to create a hierarchical menu structure with parent and child items. You can then customize the menu by setting various properties such as the menu items, links, and styling.

// Install HTML_Menu package using Composer
composer require pear/html_menu

// Include the HTML_Menu package
require_once 'HTML/Menu.php';

// Create a new HTML_Menu object
$menu = new HTML_Menu();

// Define the menu structure with parent and child items
$menu->addEntry('Parent 1', '#', array(
    'Child 1' => 'child1.php',
    'Child 2' => 'child2.php',
));

$menu->addEntry('Parent 2', '#', array(
    'Child 3' => 'child3.php',
    'Child 4' => 'child4.php',
));

// Output the menu
echo $menu->get();