title: PHP Search deep nested array for multiple key/value combinations
body: <p>I have a deep nested multidimensional array. I'm wanting to be able to search for multiple key/value pairs and return it's parent matches.</p>
  
  <p>Example array:</p>
  
  <pre><code>//$array
  Array
  (
  [0] =&gt; Array
          [ID] =&gt; 1
          [Name] =&gt; My Name
          [GroupLocations] =&gt; Array
              (
                  [0] =&gt; Array
                      (
  
                          [GroupId] =&gt; 111
                          [LocationId] =&gt; 222 
                          [Location] =&gt; Array
                              (
                                  [Name] =&gt; My Location
                                  [Street1] =&gt; 555 Somewhere Lane
                                  [City] =&gt; City
                                  [County] =&gt; County
                                  [State] =&gt; CA
                                  [Country] =&gt; US
                                  [PostalCode] =&gt; 00000
                              )
                      )
  
              )
      )
  [1] =&gt; Array
          [ID] =&gt; 2
          [Name] =&gt; My Other Name
          [GroupLocations] =&gt; Array
              (
                  [0] =&gt; Array
                      (
  
                          [GroupId] =&gt; 222
                          [LocationId] =&gt; 333 
                          [Location] =&gt; Array
                              (
                                  [Name] =&gt; My Other Location
                                  [Street1] =&gt; 666 Other Rd.
                                  [City] =&gt; City
                                  [County] =&gt; County
                                  [State] =&gt; CA
                                  [Country] =&gt; US
                                  [PostalCode] =&gt; 00000
                              )
                      )
  
              )
      )
  )
  </code></pre>
  
  <p>Something similar to <a href="https://stackoverflow.com/questions/13923524/php-search-an-array-for-multiple-key-value-pairs">PHP Search an Array for multiple key / value pairs</a> but accounting for the deeper levels.</p>
  
  <p>So if I have the example array above and want to filter the array and get results based off of filters that need to search different nested parts of the array</p>
  
  <pre><code>$filters = array(
    'ID' =&gt; $_GET[‘ID’],
    'LocationId' =&gt; $_GET['LocationId']
  );
  
  $results = filterMyArray($array, $filters);
  </code></pre>
  
  <p>Where filterMyArray function would recursively filter all levels with the array of filters and return all matching indexes/.  Struggling to come up with a decent solution.  Any suggestions on how to accomplish this?</p>