Тут, скорее всего, только рекурсией. Что-то вроде такого:
$data = array(0 => array(273 => 'Business', 317 => 'Rent', 377 => 'Places'),
273 => array(1676 => 'Corporations', 775 => 'Vacations', 1384 => 'Services'),
317 => array(774 => 'Car', 901 => 'Bike'),
377 => array(520 => 'Restaurants', 364 => 'Bars', 767 => 'Parcks')
);
function makeTree($data, $level, $root) {
if (!isset($data[$root]))
return "";
$str = "";
foreach($data[$root] as $id => $name) {
$str .= "<li data-id='{$id}' class='level{$level}'>${name}";
$str .= makeTree($data, $level+1, $id);
}
return ("" == $str ? "" : "<ul>{$str}</ul>");
}
print makeTree($data, 0, 0);
- Business
- Corporations
- Vacations
- Services
- Rent
- Places