wp_array_slice_assoc

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

Description

(array) wp_array_slice_assoc( (array) $array, (array) $keys ); 

Returns (array)

The array slice.

Parameters (2)

0. $array (array)
The original array.
1. $keys (array)
The list of keys.

Usage

  1. if ( !function_exists( 'wp_array_slice_assoc' ) ) { 
  2. require_once ABSPATH . WPINC . '/functions.php'; 
  3.  
  4. // The original array. 
  5. $array = array(); 
  6.  
  7. // The list of keys. 
  8. $keys = array(); 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = wp_array_slice_assoc($array, $keys); 
  12.  

Defined (1)

The function is defined in the following location(s).

/wp-includes/functions.php  
  1. function wp_array_slice_assoc( $array, $keys ) { 
  2. $slice = array(); 
  3. foreach ( $keys as $key ) 
  4. if ( isset( $array[ $key ] ) ) 
  5. $slice[ $key ] = $array[ $key ]; 
  6.  
  7. return $slice;