Function
Map a user defined callback to an array recursively.
tml_array_map_recursive( string $callback, array $array )
Parameters
-
$callbackstring - The name of the callback.
-
$arrayarray - The array to be mapped.
Return
array
The resulting array.
Source
function tml_array_map_recursive( $callback, $array ) { // phpcs:ignore Universal.NamingConventions.NoReservedKeywordParameterNames.arrayFound -- public API parameter name, renaming risks breaking PHP 8 named-argument callers.
foreach ( $array as $key => $value ) {
if ( is_array( $value ) ) {
$array[ $key ] = tml_array_map_recursive( $callback, $value );
} else {
$array[ $key ] = call_user_func( $callback, $value );
}
}
return $array;
}
Uses
Used by
Changelog
| Version | Description |
|---|---|
| 7.0.16 | Introduced. |