_rest_array_intersect_key_recursive() WordPress Function

The rest_array_intersect_key_recursive() function is used to intersect two arrays using the provided keys. This function is similar to the array_intersect_key() function, except that it recursively intersects arrays of arrays.

_rest_array_intersect_key_recursive( array $array1, array $array2 ) #

Recursively computes the intersection of arrays using keys for comparison.


Parameters

$array1

(array)(Required)The array with master keys to check.

$array2

(array)(Required)An array to compare keys against.


Top ↑

Return

(array) An associative array containing all the entries of array1 which have keys that are present in all arguments.


Top ↑

Source

File: wp-includes/rest-api.php

function _rest_array_intersect_key_recursive( $array1, $array2 ) {
	$array1 = array_intersect_key( $array1, $array2 );
	foreach ( $array1 as $key => $value ) {
		if ( is_array( $value ) && is_array( $array2[ $key ] ) ) {
			$array1[ $key ] = _rest_array_intersect_key_recursive( $value, $array2[ $key ] );
		}
	}
	return $array1;
}


Top ↑

Changelog

Changelog
VersionDescription
5.3.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.