Title: _rest_array_intersect_key_recursive
Published: November 12, 2019
Last modified: February 24, 2026

---

# _rest_array_intersect_key_recursive( array $array1, array $array2 ): array

## In this article

 * [Parameters](https://developer.wordpress.org/reference/functions/_rest_array_intersect_key_recursive/?output_format=md#parameters)
 * [Return](https://developer.wordpress.org/reference/functions/_rest_array_intersect_key_recursive/?output_format=md#return)
 * [Source](https://developer.wordpress.org/reference/functions/_rest_array_intersect_key_recursive/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/functions/_rest_array_intersect_key_recursive/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/functions/_rest_array_intersect_key_recursive/?output_format=md#changelog)

[ Back to top](https://developer.wordpress.org/reference/functions/_rest_array_intersect_key_recursive/?output_format=md#wp--skip-link--target)

Recursively computes the intersection of arrays using keys for comparison.

## 󠀁[Parameters](https://developer.wordpress.org/reference/functions/_rest_array_intersect_key_recursive/?output_format=md#parameters)󠁿

 `$array1`arrayrequired

The array with master keys to check.

`$array2`arrayrequired

An array to compare keys against.

## 󠀁[Return](https://developer.wordpress.org/reference/functions/_rest_array_intersect_key_recursive/?output_format=md#return)󠁿

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

## 󠀁[Source](https://developer.wordpress.org/reference/functions/_rest_array_intersect_key_recursive/?output_format=md#source)󠁿

    ```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;
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/rest-api.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/6.9.4/src/wp-includes/rest-api.php#L908)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/6.9.4/src/wp-includes/rest-api.php#L908-L916)

## 󠀁[Related](https://developer.wordpress.org/reference/functions/_rest_array_intersect_key_recursive/?output_format=md#related)󠁿

| Uses | Description | 
| [_rest_array_intersect_key_recursive()](https://developer.wordpress.org/reference/functions/_rest_array_intersect_key_recursive/)`wp-includes/rest-api.php` |

Recursively computes the intersection of arrays using keys for comparison.

  |

| Used by | Description | 
| [_rest_array_intersect_key_recursive()](https://developer.wordpress.org/reference/functions/_rest_array_intersect_key_recursive/)`wp-includes/rest-api.php` |

Recursively computes the intersection of arrays using keys for comparison.

  | 
| [rest_filter_response_fields()](https://developer.wordpress.org/reference/functions/rest_filter_response_fields/)`wp-includes/rest-api.php` |

Filters the REST API response to include only an allow-listed set of response object fields.

  |

## 󠀁[Changelog](https://developer.wordpress.org/reference/functions/_rest_array_intersect_key_recursive/?output_format=md#changelog)󠁿

| Version | Description | 
| [5.3.0](https://developer.wordpress.org/reference/since/5.3.0/) | Introduced. |

## User Contributed Notes

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2F_rest_array_intersect_key_recursive%2F)
before being able to contribute a note or feedback.