Tribe__Utils__Array::filter_prefixed( array $array, string $prefix )
Filters an associative array non-recursively, keeping only the values attached to keys starting with the specified prefix.
Contents
Parameters
- $array
-
(array) (Required) The array to filter.
- $prefix
-
(string) (Required) The prefix, or prefixes, of the keys to keep.
Return
(array) The filtered array.
Source
File: src/Tribe/Utils/Array.php
public static function filter_prefixed( array $array, $prefix ) {
$prefixes = implode( '|', array_map( 'preg_quote', (array) $prefix ) );
$pattern = '/^(' . $prefixes . ')/';
$filtered = [];
foreach ( $array as $key => $value ) {
if ( ! preg_match( $pattern, $key ) ) {
continue;
}
$filtered[ $key ] = $value;
}
return $filtered;
}
Changelog
| Version | Description |
|---|---|
| 4.9.5 | Introduced. |