Posted By

karmacode on 01/29/10


Tagged

php


Versions (?)

Flatten an array in PHP


 / Published in: PHP
 

This will outpu a numeric result array

  1. function array_flatten($array, $flat = false)
  2. {
  3. if (!is_array($array) || empty($array)) return '';
  4. if (empty($flat)) $flat = array();
  5.  
  6. foreach ($array as $key => $val) {
  7. if (is_array($val)) $flat = array_flatten($val, $flat);
  8. else $flat[] = $val;
  9. }
  10.  
  11. return $flat;
  12. }

Report this snippet  

You need to login to post a comment.