[eluser]skunkbad[/eluser]
I came up with what will be the best solution for my needs. I studied other recursive menus, including my own that are working, and this was the answer:
Code:
<?php
// Function for displaying a list.
// Receives one argument: an array.
function make_list ($child, $parents='')
{
// Need the main $categories array:
global $categories;
// Start a list:
echo '<ul>';
// Loop through each subarray:
foreach ($child as $cat_id => $cat_name)
{
// Display the item:
echo "<li><a href='" . strtolower( "$parents" . "/" . "$cat_name"). "'>$cat_name</a>";
// Check for children:
if (isset($categories[$cat_id]))
{
// Add parents to URL if applicable
$new_parents = $parents . '/' . $cat_name;
// Do recursion:
make_list($categories[$cat_id], $new_parents);
}
// Complete the list item:
echo '</li>';
}
// Close the list:
echo '</ul>';
} // End of make_list() function.
// $categories['parent_id']['category_id'] = 'category_name';
$categories[0][1] = 'Shirts';
$categories[1][2] = 'Mens';
$categories[0][3] = 'Pants';
$categories[3][4] = 'Tight';
$categories[3][5] = 'Loose';
$categories[5][6] = 'With_Belt_Buckles';
$categories[3][7] = 'Baggy';
$categories[5][8] = 'With_Suspenders';
$categories[0][9] = 'Shoes';
$categories[6][10] = 'Green';
// For debugging:
//echo '<pre>' . print_r($categories,1) . '</pre>';
// Send the first array element
// to the make_list() function:
make_list($categories[0]);
?>
Short but sweet!