seems to be a bit tricky, and im stuck on this since yesterday:

i have my navigation structure in a database. my query and everything
is ok, and i get this result:
(cut down here to keep it simple)

Array
(
    [0] => Array
        (
            [name] => Features
            [depth] => 4
        )

    [1] => Array
        (
            [name] => Administration
            [depth] => 5
        )

    [2] => Array
        (
            [name] => Reliability
            [depth] => 5
        )

    [3] => Array
        (
            [name] => Performance
            [depth] => 5
        )


    [4] => Array
        (
            [name] => FAQ
            [depth] => 4
        )


    [5] => Array
        (
            [name] => Photos
            [depth] => 4
        )

    [6] => Array
        (
            [name] => More photos
            [depth] => 5
        )

    [7] => Array
        (
            [name] => Even more photos
            [depth] => 6
        )

)

depth indicated the 2nd dimension in my menu here. this is my sidebar
only, so elements with depth 0-3 are already taken care of somewhere
else.

how can i adjust the array so that everything with depth 5 gets
attached to the previous depth 4 (and 6 to the previous depth 5 and so
on) element so that it looks like this one:

    [0] => Array
        (
            [name] => Features
            [depth] => 4
            [0] => Array
                (
                    [0] => Array
                            (
                                [name] => Administration
                                [depth] => 5
                            )

                    [1] => Array
                            (
                                [name] => Reliability
                                [depth] => 5
                            )

                    [2] => Array
                            (
                                [name] => Performance
                                [depth] => 5
                            )
                )
            [1] => Array
                (
                    [name] => FAQ
                    [depth] => 4
                )

            [2] => Array
                (
                    [name] => Photos
                    [depth] => 4
                )

                    [0] => Array
                        (
                            [name] => More photos
                            [depth] => 5
                        )

                            [0] => Array
                                (
                                    [name] => Even more photos
                                    [depth] => 6
                                )



this is what i have so far:

<?php

//testdata for your convinience :)
$data = array();
$data[0]['name'] = 'Features';
$data[0]['depth'] = 4;
$data[1]['name'] = 'Administration';
$data[1]['depth'] = 5;
$data[2]['name'] = 'Reliability';
$data[2]['depth'] = 5;
$data[3]['name'] = 'FAQ';
$data[3]['depth'] = 5;
$data[4]['name'] = 'Photos';
$data[4]['depth'] = 4;
$data[5]['name'] = 'More photos';
$data[5]['depth'] = 5;
$data[6]['name'] = 'Even more photos';
$data[6]['depth'] = 6;

function setNestedMenu($data, $init_depth = 4)
{
    //thats pretty fu now...
    $x=0;
    foreach($data as $i=>$val)
    {
        echo $i." - ".$init_depth." - ".$val['depth']." - ".
$val['name']."<br>";
        if($val['depth']==$init_depth)
        {
            $this->newMenu[] = $val;
            unset($data[$i]);
            $x++;
        }
        if($val['depth']>$init_depth)
        {
            $i = $x-1;
            $this->newMenu[$i][] = $this->setNestedMenu($data,
$val['depth']);
            unset($data[$i]);

        }
        if($val['depth']<$init_depth)
        {
            return $data;
        }
    }
}

?>

anyone who can still follow me with a hint to point me into the right
direction here?

--~--~---------~--~----~------------~-------~--~----~
NZ PHP Users Group: http://groups.google.com/group/nzphpug
To post, send email to [email protected]
To unsubscribe, send email to
[EMAIL PROTECTED]
-~----------~----~----~----~------~----~------~--~---

Reply via email to