函数原型
map_deep( mixed $value, callable $callback ): mixed
函数描述
Maps a function to all non-iterable elements of an array or an object.
是否弃用
未弃用
函数参数
-
$value
mixed
Required - The array, object, or scalar.
-
$callback
callable
Required - The function to map onto $value.
函数返回值
mixed The value with the callback applied to all non-arrays and non-objects inside it.
函数位置
File: wp-includes/formatting.php.
函数源码
function map_deep( $value, $callback ) {
if ( is_array( $value ) ) {
foreach ( $value as $index => $item ) {
$value[ $index ] = map_deep( $item, $callback );
}
} elseif ( is_object( $value ) ) {
$object_vars = get_object_vars( $value );
foreach ( $object_vars as $property_name => $property_value ) {
$value->$property_name = map_deep( $property_value, $callback );
}
} else {
$value = call_user_func( $callback, $value );
}
return $value;
}
源码链接
变更日志
| Version | Description |
|---|---|
| 4.4.0 | Introduced. |

