Created
August 16, 2018 05:02
-
-
Save Inzman/9b03b7ec114df236b65190611b4d72c1 to your computer and use it in GitHub Desktop.
Search multidimensional array by value
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
| $key = array_search($item_id, array_column($array_name, 'id')); | |
| ____________________________ | |
| 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