如何从这个数组构建“ul li”列表?

I have data in an array with the following structure:

$persons = array(
    array($id, $name, $parent),
    array(2, 'John Smith', 0),
    array(3, 'Steve Martin', 2),
    array(4, 'Peter Griffin', 3),
    array(5, 'Cinder Ella', 0)
);

and I would like to get a tree like this:

<ul>
    <li>John Smith</li>
    <ul>
        <li>Steve Martin</li>
        <ul>
            <li>Peter Griffin</li>
        </ul>
    </ul>
    <li>Cinder Ella</li>
</ul>

Probably this is just as easy as 1-2-3 but I have tried everything already without success...

heres a solution:

<?php

$persons = array(
array(2, 'John Smith', 0),
array(3, 'Steve Martin', 2),
array(4, 'Peter Griffin', 3),
array(5, 'Cinder Ella', 0)
);

echo "<ul>";
printChildren($persons,0);
echo '</ul>';

function printChildren($arr,$id){
foreach($arr as $subvalue)
        if($subvalue[2] == $id){
        echo '<li>'.$subvalue[1].'</li>';
    if(countChildren($arr,$subvalue[0])>0){
        echo '<ul>';
        printChildren($arr,$subvalue[0]);
        echo '</ul>';
    }
}
}
function countChildren($arr,$id){
$i=0;
foreach($arr as $value){
if($value[2] == $id) $i++;
}
return $i;
}
?>
    function getChild($searchkey,$arr,&$doneArr){
                    $doneArr[] = $searchkey;
                    foreach($arr as $valArr){
                            if($key = array_search($searchkey,$valArr)){
                                    $id = $valArr[0];
                                    $name = $valArr[1];
                                    $parent = $valArr[2];
                                    if(!in_array($id,$doneArr)){
                                            $html = '<ul>';
                                            $html .= '<li>'.$name.'</li>';
                                            $html .= getChild($id,$arr,$doneArr); // used to get recursively all childs
                                            $html .= '</ul>';
                                    }
                            }
                    }
                    return $html;
            }
            $html = '<ul>';
            $cnt = sizeof($persons);
            $doneArr = Array(); // used to maintain processed items.
            for($i=0;$i<$cnt;$i++){
                    $id = $persons[$i][0];
                    $name = $persons[$i][1];
                    $parent = $persons[$i][2];
                    if(empty($parent)){
                            $html .= '<li>'.$name.'</li>';
                    }
                    $html .= getChild($id,$persons,$doneArr);
            }

            $html .= '</ul>';
            echo $html;
            unset($doneArr);