Return to Snippet

Revision: 23060
at January 29, 2010 01:19 by karmacode


Initial Code
function array_flatten($array, $flat = false)
{
    if (!is_array($array) || empty($array)) return '';
    if (empty($flat)) $flat = array();
       
    foreach ($array as $key => $val) {
      if (is_array($val)) $flat = array_flatten($val, $flat);
      else $flat[] = $val;
    }
       
    return $flat;
}

Initial URL

                                

Initial Description
This will outpu a numeric result array

Initial Title
Flatten an array in PHP

Initial Tags
php

Initial Language
PHP