GC_Customize_Setting::multidimensional()

最后更新于:2021-11-27 08:42:59

GC_Customize_Setting::multidimensional( array$root, array$keys, bool$create=false)

Multidimensional helper function.

参数

$root

(array) (Required)

$keys

(array) (Required)

$create

(bool) (Optional)

Default value: false

响应

(array|void) Keys are ‘root’, ‘node’, and ‘key’.

源文件

文件: gc-includes/class-gc-customize-setting.php

	final protected function multidimensional( &$root, $keys, $create = false ) {
		if ( $create && empty( $root ) ) {
			$root = array();
		}

		if ( ! isset( $root ) || empty( $keys ) ) {
			return;
		}

		$last = array_pop( $keys );
		$node = &$root;

		foreach ( $keys as $key ) {
			if ( $create && ! isset( $node[ $key ] ) ) {
				$node[ $key ] = array();
			}

			if ( ! is_array( $node ) || ! isset( $node[ $key ] ) ) {
				return;
			}

			$node = &$node[ $key ];
		}

		if ( $create ) {
			if ( ! is_array( $node ) ) {
				// Account for an array overriding a string or object value.
				$node = array();
			}
			if ( ! isset( $node[ $last ] ) ) {
				$node[ $last ] = array();
			}
		}

		if ( ! isset( $node[ $last ] ) ) {
			return;
		}

		return array(
			'root' => &$root,
			'node' => &$node,
			'key'  => $last,
		);
	}