beans_in_multi_array

Checks if a value exists in a multi-dimensional array.

beans_in_multi_array( string $needle, array $haystack, bool $strict = false )

Return: (bool) True if needle is found in the array, false otherwise.

Parameters

NameTypeRequiredDefaultDescription
$needlestringtrue-The searched value.
$haystackarraytrue-The multi-dimensional array.
$strictbooltruefalseIf the third parameter strict is set to true, the beans_in_multi_array() function will also check the types of the needle in the haystack.

Source

function beans_in_multi_array( $needle, $haystack, $strict = false ) {

	if ( in_array( $needle, $haystack, $strict ) ) {
		return true;
	}

	foreach ( (array) $haystack as $value ) {
		if ( is_array( $value ) && beans_in_multi_array( $needle , $value ) ) {
			return true;
		}
	}

	return false;

}