WP_View_Config_Data::merge_list_by_identity( array $current, array $incoming ): array

This function’s access is marked private. This means it is not intended for use by plugin or theme developers, only by core. It is listed here for completeness.

Merges an incoming list into the current one by member identity.

Description

A member of the incoming list whose identity matches one already present merges into it in place, keeping its position; an unmatched member is appended to the end, except a literal null, which carries no identity and holds nothing to merge and so is dropped. An appended member has no existing leaf for a nested null to delete (the same rationale as set()), so its nulls are stripped rather than stored. A matched member’s contents merge recursively with the same rules (merge_properties), so the identity-aware merge applies at any nesting level: each key named by the patch is substituted while the others are left intact, and a list nested inside a member merges by identity just like the list it lives in.

Parameters

$currentarrayrequired
The current list.
$incomingarrayrequired
The incoming list.

Return

array The merged list.

Source

private function merge_list_by_identity( array $current, array $incoming ) {
	$result = $current;
	foreach ( $incoming as $item ) {
		// A null member carries no identity and holds nothing to merge,
		// so it is dropped rather than appended as a literal null.
		if ( null === $item ) {
			continue;
		}

		$identity = $this->list_item_identity( $item );

		// Find the index of the existing member with the same identity, if any.
		// If there's none, append the incoming member to the end of the list.
		$index = null;
		if ( null !== $identity ) {
			foreach ( $result as $i => $existing ) {
				if ( $this->list_item_identity( $existing ) === $identity ) {
					$index = $i;
					break;
				}
			}
		}
		if ( null === $index ) {
			// An appended member has no existing leaf for a nested null to
			// delete, so nulls are dropped rather than stored.
			$result[] = $this->strip_nulls( $item );
			continue;
		}

		// Otherwise, merge the incoming member into the existing one in place.
		$result[ $index ] = $this->merge_properties( $result[ $index ], $item, false );
	}

	return $result;
}

Changelog

VersionDescription
7.1.0Introduced.

User Contributed Notes

You must log in before being able to contribute a note or feedback.