If you need list with ul, li tags, try to use this code. It should work.
$lastLvl = 1;
echo '<ul>';
foreach ($array as $object) {
if ($object->lvl < $lastLvl) {
for ($i = 1; $i <= ($lastLvl - $object->lvl); $i++)
echo '</ul>';
}
if ($object->lvl > $lastLvl) {
for ($i = 1; $i <= ($object->lvl - $lastLvl); $i++)
echo '<ul>';
}
echo '<li>', $object->name, '</li>';
$lastLvl = $object->lvl;
}
for ($i = 1; $i <= $lastLvl; $i++)
echo '</ul>';
solved create html list from array with levels