wp_array_slice_assoc( array $input_array, array $keys ): array

Extracts a slice of an array, given a list of keys.

Parameters

$input_arrayarrayrequired
The original array.
$keysarrayrequired
The list of keys.

Return

array The array slice.

Source

function wp_array_slice_assoc( $input_array, $keys ) {
	$slice = array();

	foreach ( $keys as $key ) {
		if ( isset( $input_array[ $key ] ) ) {
			$slice[ $key ] = $input_array[ $key ];
		}
	}

	return $slice;
}

Changelog

VersionDescription
3.1.0Introduced.

User Contributed Notes

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