Skip to content

Instantly share code, notes, and snippets.

@dellow
Last active October 5, 2021 10:13
Show Gist options
  • Save dellow/7f7f89d43da14a06121e to your computer and use it in GitHub Desktop.
Save dellow/7f7f89d43da14a06121e to your computer and use it in GitHub Desktop.
Multi dimensional array_search().
/**
* 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