Recursion: Ugh!

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi everyone,

I've been working on a problem for a few days now and I'm not making any
headway so I think it's time I come to the list for some help (though
this really disappoints me since it appears I'm not capable of solving
this problem on my own!).

Anyway, I'm using the Modified Preorder Tree Traversal method to store
my category hierarchy. Using recursion I can build an array that
accurately depicts the layout of the categories. So far so good. What I
have not been able to do thus far is turn that array into a list that
looks like this:

Food:Fruit:Red
Food:Fruit:Green
Food:Fruit:Yellow
Food:Vegetables:Long
Food:Vegetables:Round
Food:Vegetables:Round:Spikey
Food:Vegetables:Round:Smooth

My array is included at the end of this email. (And yes I typed it by
hand so hopefully there aren't any errors in it.)

I've searched the web but haven't found anything that's helped.

Anyone have a solution?

Thanks,
Chris.

0 => Array
   (
      [name] => Food
      [children] => Array
         (
            0 => Array
               (
                  [name] => Fruit
                  [children] => Array
                     (
                        0 => Array
                           (
                              [name] => Red
                              [children] =>
                           )

                        1 => Array
                           (
                              [name] => Green
                              [children] =>
                           )

                        2 => Array
                           (
                              [name] => Yello
                              [children] =>
                           )
                     )
               )

            1 => Array
               (
                  [name] => Vegetables
                  [children] => Array
                     (
                        0 => Array
                           (
                              [name] => Long
                              [children] =>
                           )

                        1 => Array
                           (
                              [name] => Round
                              [children] => Array
                                 (
                                    0 => Array
                                       (
                                          [name] => Spikey
                                          [children] =>
                                       )

                                    1 => Array
                                       (
                                          [name] => Smooth
                                          [children] =>
                                       )
                                 )
                           )
                     )
               )
         )
   )

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux