_wp_array_get
函数
_wp_array_get ( $array, $path, $default = null )
- Access
- Private
- 参数
-
-
(array)
$array
An array from which we want to retrieve some information.- Required: 是
-
(array)
$path
An array of keys describing the path with which to retrieve information.- Required: 是
-
(mixed)
$default
Optional. The return value if the path does not exist within the array, or if `$array` or `$path` are not arrays. Default null.- Required: 否
- Default: null
-
(array)
- 返回值
-
- (mixed) The value from the path specified.
- 定义位置
-
-
wp-includes/functions.php
, line 4911
-
wp-includes/functions.php
- 引入
- 5.6.0
- 弃用
- –
Accesses an array in depth based on a path of keys.
It is the PHP equivalent of JavaScript’s `lodash.get()` and mirroring it may help other components
retain some symmetry between client and server implementations.
Example usage:
$array = array(
‘a’ => array(
‘b’ => array(
‘c’ => 1,
),
),
);
_wp_array_get( $array, array( ‘a’, ‘b’, ‘c’ ) );
function _wp_array_get( $array, $path, $default = null ) { // Confirm $path is valid. if ( ! is_array( $path ) || 0 === count( $path ) ) { return $default; } foreach ( $path as $path_element ) { if ( ! is_array( $array ) || ( ! is_string( $path_element ) && ! is_integer( $path_element ) && ! is_null( $path_element ) ) || ! array_key_exists( $path_element, $array ) ) { return $default; } $array = $array[ $path_element ]; } return $array; }
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。