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
Name | Type | Required | Default | Description |
---|---|---|---|---|
$needle | string | true | - | The searched value. |
$haystack | array | true | - | 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;
}