title: Recursive array_search
body: <p>I have a multi-dimensional array:</p>
  
  <pre><code>$categories = array(
      array(
          'CategoryID' =&gt; 14308,
          'CategoryLevel' =&gt; 1,
          'CategoryName' =&gt; 'Alcohol &amp; Food',
          'CategoryParentID' =&gt; 14308
      ),
      // CHILD CATEGORIES
      array(
          array(
              'CategoryID' =&gt; 179836,
              'CategoryLevel' =&gt; 2,
              'CategoryName' =&gt; 'Alcohol &amp; Alcohol Mixes',
              'CategoryParentID' =&gt; 14308
          ),
          array(
              array(
                  'CategoryID' =&gt; 172528,
                  'CategoryLevel' =&gt; 2,
                  'CategoryName' =&gt; 'Antipasto, Savoury',
                  'CategoryParentID' =&gt; 14308
              )
          )
      )
  );
  </code></pre>
  
  <p>I need to get the exact location of the index, and since <code>array_search</code> doesn't work on multi-dimensional arrays, I'm using one of the functions provided on the PHP manual page.</p>
  
  <pre><code>function recursive_array_search($needle,$haystack) {
      foreach($haystack as $key=&gt;$value) {
          $current_key=$key;
          if($needle===$value OR (is_array($value) &amp;&amp; recursive_array_search($needle,$value) !== false)) {
              return $current_key;
          }
      }
      return false;
  }
  </code></pre>
  
  <p>.. but it also returns the key of the first array only:</p>
  
  <pre><code>echo recursive_array_search(172528, $categories); // outputs 1
  </code></pre>
  
  <p>I'm expecting: </p>
  
  <pre><code>[1][1][0]
  </code></pre>