W3cubDocs

/WordPress

wp_array_slice_assoc( array $array, array $keys )

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

Description

Parameters

$array

(array) (Required) The original array.

$keys

(array) (Required) The list of keys.

Return

(array) The array slice.

Source

File: wp-includes/functions.php

function wp_array_slice_assoc( $array, $keys ) {
	$slice = array();
	foreach ( $keys as $key ) {
		if ( isset( $array[ $key ] ) ) {
			$slice[ $key ] = $array[ $key ];
		}
	}

	return $slice;
}

Changelog

Version Description
3.1.0 Introduced.

© 2003–2019 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/functions/wp_array_slice_assoc