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