WordPress at Your Fingertips

wp_array_slice_assoc() WP 1.0

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

1 time — 0.000017 sec (very fast) | 50000 times — 0.08 sec (speed of light) | PHP 7.0.4, WP 4.4.2

No Hooks.

Return

Array. The array slice.

Usage

wp_array_slice_assoc( $array, $keys );
$array(array) (required)
The original array.
$keys(array) (required)
The list of keys.

Changelog

Since 3.1.0 Introduced.

Code of wp_array_slice_assoc() WP 5.8.1

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

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

	return $slice;
}

array list help functions (sorting arrays objects)

Helper Functions

No comments
    Log In