beans_multi_array_key_exists

Checks if a key or index exists in a multi-dimensional array.

beans_multi_array_key_exists( string $needle, array $haystack )

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

Parameters

NameTypeRequiredDefaultDescription
$needlestringtrue-The searched value.
$haystackarraytrue-The multi-dimensional array.

Source

function beans_multi_array_key_exists( $needle, $haystack ) {

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

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

	return false;

}