Created
May 14, 2020 02:30
-
-
Save trvswgnr/c0100162d3ef4b7dfb6a10518c2f0781 to your computer and use it in GitHub Desktop.
Find array item by key value in multilevel array.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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