Find the right value in recursive array

Posted by fire on Stack Overflow See other posts from Stack Overflow or by fire
Published on 2010-04-16T13:49:49Z Indexed on 2010/04/16 13:53 UTC
Read the original article Hit count: 207

Filed under:

I have an array with multiple sub-arrays like this:

    Array
   (
       [0] => Array
           (
               [Page_ID] => 1
               [Page_Parent_ID] => 0
               [Page_Title] => Overview
               [Page_URL] => overview
               [Page_Type] => content
               [Page_Order] => 1
           )

       [1] => Array
           (
               [0] => Array
                   (
                       [Page_ID] => 2
                       [Page_Parent_ID] => 1
                       [Page_Title] => Team
                       [Page_URL] => overview/team
                       [Page_Type] => content
                       [Page_Order] => 1
                   )

           )

       [2] => Array
           (
               [Page_ID] => 3
               [Page_Parent_ID] => 0
               [Page_Title] => Funds
               [Page_URL] => funds
               [Page_Type] => content
               [Page_Order] => 2
           )

       [3] => Array
           (
               [0] => Array
                   (
                       [Page_ID] => 4
                       [Page_Parent_ID] => 3
                       [Page_Title] => Strategy
                       [Page_URL] => funds/strategy
                       [Page_Type] => content
                       [Page_Order] => 1
                   )

               [1] => Array
                   (
                       [0] => Array
                           (
                               [Page_ID] => 7
                               [Page_Parent_ID] => 4
                               [Page_Title] => A Class Fund
                               [Page_URL] => funds/strategy/a-class-fund
                               [Page_Type] => content
                               [Page_Order] => 1
                           )

                       [1] => Array
                           (
                               [0] => Array
                                   (
                                       [Page_ID] => 10
                                       [Page_Parent_ID] => 7
                                       [Page_Title] => Information
                                       [Page_URL] => funds/strategy/a-class-fund/information
                                       [Page_Type] => content
                                       [Page_Order] => 1
                                   )

                               [1] => Array
                                   (
                                       [Page_ID] => 11
                                       [Page_Parent_ID] => 7
                                       [Page_Title] => Fund Data
                                       [Page_URL] => funds/strategy/a-class-fund/fund-data
                                       [Page_Type] => content
                                       [Page_Order] => 2
                                   )

                           )

                       [2] => Array
                           (
                               [Page_ID] => 8
                               [Page_Parent_ID] => 4
                               [Page_Title] => B Class Fund
                               [Page_URL] => funds/strategy/b-class-fund
                               [Page_Type] => content
                               [Page_Order] => 2
                           )

I need a function to find the right Page_URL so if you know the $url is "funds/strategy/a-class-fund" I need to pass that to a function that returns a single array result (which would be the Page_ID = 7 array in this example).

Having a bit of a stupid day, any help would be appreciated!

© Stack Overflow or respective owner

Related posts about php