note 44933 deleted from function.sort by tomsommer
| From: | tomsommer@php.net | Date: | Fri, 20 Aug 2004 18:08:50 +0000 |
| Subject: | note 44933 deleted from function.sort by tomsommer | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-75014@lists.php.net to get a copy of this message | ||
Note Submitter: lsblsb at gmx dot de [germany]
----
hello,
i just finished a nice recursive function. took me some hours (50% caused by stupid
standard-mistakes). but well - its done.
I wrote it, cause i organized the tree-structure of a menu-class creating html-menus easily like
that:
"0" is first entry on highest hierarchy.
"00" is first entry on second hierarchy, that comes after "0".
"1" is second entry on highest hierarchy.
"10" is first entry on second hierarchy, that comes after "1".
etc.
Now I needed a function that can easily parse through an array that has all existing tree-entries in
it (unsorted), cause I want to write a class that can output the menu like a tree, similar to common
file-explorers.
Maybe someone needs it too.
And thats it - little but smart ;) :
function draw_tree($node_arr, $akt_node="")
{
if(!empty($node_arr))
{
for($i=0; $i<10; $i++)
{
$tmp_node = $akt_node.$i;
$in_array = false;
if(in_array($tmp_node,$node_arr))
{
$depth = strlen($tmp_node)-1;
echo(str_repeat(">",$depth).$tmp_node."<br>");
draw_tree($node_arr, $tmp_node);
}
}
}
}
//needs an array like that:
$node_arr = array("0","10","1","00");
//call
draw_tree($node_arr);
bye lars