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.
Example array:
//$array
Array
(
[0] => Array
[ID] => 1
[Name] => My Name
[GroupLocations] => Array
(
[0] => Array
(
[GroupId] => 111
[LocationId] => 222
[Location] => Array
(
[Name] => My Location
[Street1] => 555 Somewhere Lane
[City] => City
[County] => County
[State] => CA
[Country] => US
[PostalCode] => 00000
)
)
)
)
[1] => Array
[ID] => 2
[Name] => My Other Name
[GroupLocations] => Array
(
[0] => Array
(
[GroupId] => 222
[LocationId] => 333
[Location] => Array
(
[Name] => My Other Location
[Street1] => 666 Other Rd.
[City] => City
[County] => County
[State] => CA
[Country] => US
[PostalCode] => 00000
)
)
)
)
)
Something similar to PHP Search an Array for multiple key / value pairs but accounting for the deeper levels.
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
$filters = array(
'ID' => $_GET[‘ID’],
'LocationId' => $_GET['LocationId']
);
$results = filterMyArray($array, $filters);
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?