芝麻web文件管理V1.00
编辑当前文件:/home/fambnfli/www/tr/wp-content/plugins/meta-box/vendor/meta-box/support/Arr.php
$value ) { self::set( $output, $key, $value ); if ( is_array( $value ) && ! strpos( $key, '.' ) ) { $nested = self::unflatten( $value ); $output[ $key ] = $nested; } } return $output; } /** * Set array element value with dot notation. */ public static function set( &$array, $key, $value ) { if ( is_null( $key ) ) { $array = $value; return $array; } // Do not parse email value. if ( is_email( $key ) ) { $array[ $key ] = $value; return; } $keys = explode( '.', $key ); while ( count( $keys ) > 1 ) { $key = array_shift( $keys ); // If the key doesn't exist at this depth, we will just create an empty array // to hold the next value, allowing us to create the arrays to hold final // values at the correct depth. Then we'll keep digging into the array. if ( ! isset( $array[ $key ] ) || ! is_array( $array[ $key ] ) ) { $array[ $key ] = []; } $array =& $array[ $key ]; } $array[ array_shift( $keys ) ] = $value; } /** * Get array element value with dot notation. */ public static function get( $array, $key, $default = null ) { if ( is_null( $key ) ) { return $array; } $keys = explode( '.', $key ); foreach ( $keys as $key ) { if ( isset( $array[ $key ] ) ) { $array = $array[ $key ]; } else { return $default; } } return $array; } public static function to_depth( $input, $depth ) { $current_depth = is_array( $input ) ? self::depth( $input ) : 0; if ( $depth < $current_depth ) { while ( $current_depth > $depth ) { $input = reset( $input ); $current_depth--; } } elseif ( $depth > $current_depth ) { while ( $current_depth < $depth ) { $input = [ $input ]; $current_depth++; } } return $input; } public static function depth( array $array ) { $max_depth = 1; foreach ( $array as $key => $value ) { if ( !is_string($key) && is_array( $value ) ) { $depth = self::depth( $value ) + 1; if ( $depth > $max_depth ) { $max_depth = $depth; } } } return $max_depth; } public static function remove_first( &$array, $query ) { $keys = explode( '.', $query ); $key = array_shift( $keys ); if ( count( $keys ) === 0 ) { if ( is_array( $array ) && array_key_exists( $key, $array ) ) { unset( $array[ $key ][0] ); } return; } if ( $key === '*' ) { foreach ( $array as $k => $v ) { if ( is_array( $array[ $k ] ) ) { self::remove_first( $array[ $k ], implode( '.', $keys ) ); } } return; } if ( $key === '' ) { return; } if ( is_array( $array[ $key ] ) ) { self::remove_first( $array[ $key ], implode( '.', $keys ) ); } } }