Posted By

jatkins on 02/02/17


Tagged


Versions (?)

Flatten array


 / Published in: PHP
 

Released into the public domain by Josh Atkins, 2017.

  1. function flattenArray($arrayToFlatten) {
  2. $flatArray = array();
  3. foreach($arrayToFlatten as $element) {
  4. if (is_array($element)) {
  5. $flatArray = array_merge($flatArray, flattenArray($element));
  6. } else {
  7. $flatArray[] = $element;
  8. }
  9. }
  10. return $flatArray;
  11. }

Report this snippet  

You need to login to post a comment.