bb_flatten_array

Utility.

Description

bb_flatten_array( $array, (int) $cut_branch = 0, (bool) $keep_child_array_keys = true ); 

Parameters (3)

0. $array
The array.
1. $cut_branch — Optional. (int)
The cut branch.
2. $keep_child_array_keys — Optional. (bool) => true
The keep child array keys.

Usage

  1. if ( !function_exists( 'bb_flatten_array' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'buddypress/bp-forums/bbpress/bb-includes/functions.bb-core.php'; 
  3.  
  4. // The array. 
  5. $array = null; 
  6.  
  7. // The cut branch. 
  8. $cut_branch = -1; 
  9.  
  10. // The keep child array keys. 
  11. $keep_child_array_keys = true; 
  12.  
  13. // NOTICE! Understand what this does before running. 
  14. $result = bb_flatten_array($array, $cut_branch, $keep_child_array_keys); 
  15.  

Defined (1)

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

/bp-forums/bbpress/bb-includes/functions.bb-core.php  
  1. function bb_flatten_array( $array, $cut_branch = 0, $keep_child_array_keys = true ) { 
  2. if ( !is_array($array) ) 
  3. return $array; 
  4.  
  5. if ( empty($array) ) 
  6. return null; 
  7.  
  8. $temp = array(); 
  9. foreach ( $array as $k => $v ) { 
  10. if ( $cut_branch && $k == $cut_branch ) 
  11. continue; 
  12. if ( is_array($v) ) { 
  13. if ( $keep_child_array_keys ) { 
  14. $temp[$k] = true; 
  15. $temp += bb_flatten_array($v, $cut_branch, $keep_child_array_keys); 
  16. } else { 
  17. $temp[$k] = $v; 
  18. return $temp;