I have a MySQL table with a tree data structure. The fields are _id, name and parentId. When the record hasn\'t a parent, parent
My final solution (thanks to Starx and varan):
function toSelect ($arr, $depth=0) {
$html = '';
foreach ( $arr as $v ) {
$html.= '' . PHP_EOL;
if ( array_key_exists('children', $v) ) {
$html.= toSelect($v['children'], $depth+1);
}
}
return $html;
}
echo '';
Even the RecursiveIteratorIterator solution is good (thanks hakre).