title: Finding a path in a multidimensional array for a certain ID
body: <p>I have an array that's stored like this:</p>
  
  <pre><code>[0] =&gt; Array
      (
          [id] =&gt; 1
          [cat_name] =&gt; c1
      )
  
  [1] =&gt; Array
      (
          [id] =&gt; 2
          [cat_name] =&gt; c2
          [copii] =&gt; Array
              (
                  [0] =&gt; Array
                      (
                          [id] =&gt; 5
                          [cat_name] =&gt; c21
                      )
  
                  [1] =&gt; Array
                      (
                          [id] =&gt; 6
                          [cat_name] =&gt; c22
                      )
  
              )
  
      )
  
  [2] =&gt; Array
      (
          [id] =&gt; 3
          [cat_name] =&gt; c3
          [copii] =&gt; Array
              (
                  [0] =&gt; Array
                      (
                          [id] =&gt; 7
                          [cat_name] =&gt; c31
                          [copii] =&gt; Array
                              (
                                  [0] =&gt; Array
                                      (
                                          [id] =&gt; 9
                                          [cat_name] =&gt; c311
                                      )
  
                              )
  
                      )
  
                  [1] =&gt; Array
                      (
                          [id] =&gt; 8
                          [cat_name] =&gt; c32
                      )
  
              )
  
      )
  </code></pre>
  
  <p>I'm trying to find an easier way of finding a route to a certain ID.
  Now I'm using foreach to iterate through all possible arrays and finding the route.</p>
  
  <p>Example:</p>
  
  <pre><code>id = 1:
       route[0][id]=1,route[0][cat_name]=c1
  id = 5:
      route[0][id]=2,route[0][cat_name]=c2
      route[1][id]=5,route[1][cat_name]=c21
  id = 9:
      route[0][id]=3,route[0][cat_name]=c3
      route[1][id]=7,route[1][cat_name]=c31
      route[2][id]=9,route[2][cat_name]=c311
  </code></pre>
  
  <p>If my question makes no sense, I blame it on the hours spent trying to find a nice solution to it...</p>