Skip to content

Instantly share code, notes, and snippets.

@Mario-Duarte
Forked from kjbrum/search_for_value.php
Created January 8, 2019 17:11
Show Gist options
  • Save Mario-Duarte/d9de8b9338331feeac17b07b9766e27f to your computer and use it in GitHub Desktop.
Save Mario-Duarte/d9de8b9338331feeac17b07b9766e27f to your computer and use it in GitHub Desktop.
Check if a value exists in an array/object.
/**
* Check if a value is in a multi-dimensional array
* @param mixed $needle The value that you are searching for
* @param array $haystack The multi-dimensional array to search
* @param boolean $strict Whether to use strict search or not
* @return boolean Whether the value was found or not
*/
function in_multi_array($needle, $haystack, $strict=false) {
foreach ($haystack as $subhaystack) {
if(in_array($needle, $subhaystack, $strict))
return true;
}
return false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment