Last active
October 5, 2021 10:13
-
-
Save dellow/7f7f89d43da14a06121e to your computer and use it in GitHub Desktop.
Multi dimensional array_search().
This file contains 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
/** | |
* array_searchr | |
* Multi dimensional array_search(). | |
* | |
* @since 1.0.0 | |
* @version 1.0.0 | |
**/ | |
function array_searchr($id, $array, $key, $return = false, $query = false){ | |
$matches = array(); | |
foreach($array as $k=>$v){ | |
if($v[$key] === $id){ | |
if(is_array($query)){ | |
if($v[$query[0]] == $query[1]){ | |
$matches[] = $v; | |
} | |
} | |
else{ | |
$matches[] = (!$return) ? $v : $v[$return]; | |
} | |
} | |
} | |
return (count($matches) > 0) ? $matches : false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment