I wrote the following function to determine if a multidimensional array contains some specific value.
function findKeyValue ($array, $needle, $value, $found = false){ foreach ($array as $key => $item){ // Navigate through the array completely. if (is_array($item)){ $found = $this->findKeyValue($item, $needle, $value, $found); } // If the item is a node, verify if the value of the node contains // the given search parameter. EG: 'value' <=> 'This contains the value' if ( ! empty($key) && $key == $needle && strpos($item, $value) !== false){ return true; } } return $found; }
Call the function as follows:
$this->findKeyValue($array, $key, $value);
Guillaume Zeeman May 25 '16 at 12:45 2016-05-25 12:45
source share