wp_array_slice_assoc() WordPress Function

The wp_array_slice_assoc() function is used to slice an associative array (or object) into a new array, given a specified offset and length. This function is typically used to extract a portion of an array for use in a loop or other operation.

wp_array_slice_assoc( array $array, array $keys ) #

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


Parameters

$array

(array)(Required)The original array.

$keys

(array)(Required)The list of keys.


Top ↑

Return

(array) The array slice.


Top ↑

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


Top ↑

Changelog

Changelog
VersionDescription
3.1.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.

Show More
Show More