_rest_array_intersect_key_recursive()
Recursively computes the intersection of arrays using keys for comparison.
Internal function — this function is designed to be used by the kernel itself. It is not recommended to use this function in your code.
No Hooks.
Returns
Array. An associative array containing all the entries of array1 which have keys that are present in all arguments.
Usage
_rest_array_intersect_key_recursive( $array1, $array2 );
- $array1(array) (required)
- The array with master keys to check.
- $array2(array) (required)
- An array to compare keys against.
Changelog
| Since 5.3.0 | Introduced. |
_rest_array_intersect_key_recursive() rest array intersect key recursive code WP 7.0
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;
}