WPSEO_Meta::array_merge_recursive_distinct()public staticYoast 1.0

Recursively merge a variable number of arrays, using the left array as base, giving priority to the right array.

Difference with native array_merge_recursive(): array_merge_recursive converts values with duplicate keys to arrays rather than overwriting the value in the first array with the duplicate value in the second array.

array_merge_recursive_distinct does not change the data types of the values in the arrays. Matching keys' values in the second array overwrite those in the first array, as is the case with array_merge.

Freely based on information found on http://www.php.net/manual/en/function.array-merge-recursive.php

{@internal Should be moved to a general utility class.}}

Метод класса: WPSEO_Meta{}

Хуков нет.

Возвращает

Массив.

Использование

$result = WPSEO_Meta::array_merge_recursive_distinct();

Код WPSEO_Meta::array_merge_recursive_distinct() Yoast 22.4

public static function array_merge_recursive_distinct() {

	$arrays = func_get_args();
	if ( count( $arrays ) < 2 ) {
		if ( $arrays === [] ) {
			return [];
		}
		else {
			return $arrays[0];
		}
	}

	$merged = array_shift( $arrays );

	foreach ( $arrays as $array ) {
		foreach ( $array as $key => $value ) {
			if ( is_array( $value ) && ( isset( $merged[ $key ] ) && is_array( $merged[ $key ] ) ) ) {
				$merged[ $key ] = self::array_merge_recursive_distinct( $merged[ $key ], $value );
			}
			else {
				$merged[ $key ] = $value;
			}
		}
		unset( $key, $value );
	}

	return $merged;
}