Automattic\WooCommerce\Blocks\Utils
StyleAttributesUtils::array_get_value_by_path
Get a value from an array based on a path e.g style.elements.link
Method of the class: StyleAttributesUtils{}
No Hooks.
Returns
Mixed.
Usage
$result = StyleAttributesUtils::array_get_value_by_path( $array, $path, $delimiter );
- $array(array) (required)
- Target array.
- $path(string) (required)
- Path joined by delimiter.
- $delimiter(string)
- Chosen delimiter defaults to ".".
Default:'.'
StyleAttributesUtils::array_get_value_by_path() StyleAttributesUtils::array get value by path code WC 10.8.1
protected static function array_get_value_by_path( array &$array, $path, $delimiter = '.' ) {
$array_path = explode( $delimiter, $path );
$ref = &$array;
foreach ( $array_path as $key ) {
if ( is_array( $ref ) && array_key_exists( $key, $ref ) ) {
$ref = &$ref[ $key ];
} else {
return null;
}
}
return $ref;
}