Skip to content

Instantly share code, notes, and snippets.

@trvswgnr
Created May 14, 2020 02:30
Show Gist options
  • Save trvswgnr/c0100162d3ef4b7dfb6a10518c2f0781 to your computer and use it in GitHub Desktop.
Save trvswgnr/c0100162d3ef4b7dfb6a10518c2f0781 to your computer and use it in GitHub Desktop.
Find array item by key value in multilevel array.
function search($array, $key, $value) {
$results = array();
if (is_array($array)) {
if (isset($array[$key]) && $array[$key] == $value) {
$results[] = $array;
}
foreach ($array as $subarray) {
$results = array_merge($results, search($subarray, $key, $value));
}
}
return $results;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment