function array_flatten


/ Published in: PHP
Save to your folder(s)



Copy this code and paste it in your HTML
  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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.