Posted By

CJness on 10/01/10


Tagged

php array flatten


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

MarcelDillen


function array_flatten


 / Published in: PHP
 

  1. function array_flatten($array, &$new_array = array(), $index = '')
  2. {
  3. foreach ($array as $key => $value)
  4. {
  5. if (!empty($index))
  6. {
  7. $key = $index.'_'.$key;
  8. }
  9.  
  10. if (is_array($value))
  11. {
  12. $new_array = array_flatten($value, $new_array, $key);
  13. }
  14. else
  15. {
  16. $new_array[$key] = $value;
  17. }
  18. }
  19.  
  20. return $new_array;
  21. }

Report this snippet  

You need to login to post a comment.