Automattic\WooCommerce\Admin\RemoteSpecs\RuleProcessors\Transformers

DotNotation::getpublicWC 1.0

Find the given $path in $array_to_search by dot notation.

Method of the class: DotNotation{}

No Hooks.

Returns

Mixed|null.

Usage

$DotNotation = new DotNotation();
$DotNotation->get( $array_to_search, $path, $default_value );
$array_to_search(array) (required)
an array to search in.
$path(string) (required)
a path in the given array.
$default_value(null)
default value to return if $path was not found.
Default: null

DotNotation::get() code WC 10.4.3

public function get( $array_to_search, $path, $default_value = null ) {
	if ( ! is_array( $array_to_search ) ) {
		return $default_value;
	}

	if ( isset( $array_to_search[ $path ] ) ) {
		return $array_to_search[ $path ];
	}

	foreach ( explode( '.', $path ) as $segment ) {
		if ( ! is_array( $array_to_search ) || ! array_key_exists( $segment, $array_to_search ) ) {
			return $default_value;
		}

		$array_to_search = $array_to_search[ $segment ];
	}

	return $array_to_search;
}