array_unshift_assoc

Appends an item to the beginning of an associative array while preserving the array keys.

Description

(array) array_unshift_assoc( (array) &$arr, (scalar) $key, (mixed) $val ); 

Returns (array)

Parameters (3)

0. $arr (array) => &$arr
The arr.
1. $key (scalar)
The key.
2. $val (mixed)
The val.

Usage

  1. if ( !function_exists( 'array_unshift_assoc' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'membership-2/app/helper/class-ms-helper-utility.php'; 
  3.  
  4. // The arr. 
  5. $arr = array(); 
  6.  
  7. // The key. 
  8. $key = null; 
  9.  
  10. // The val. 
  11. $val = null; 
  12.  
  13. // NOTICE! Understand what this does before running. 
  14. $result = array_unshift_assoc($arr, $key, $val); 
  15.  

Defined (1)

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

/app/helper/class-ms-helper-utility.php  
  1. function array_unshift_assoc( &$arr, $key, $val ) { 
  2. $arr = array_reverse( $arr, true ); 
  3. $arr[$key] = $val; 
  4. return array_reverse( $arr, true );