/** * Take multi-dimensional array and return it as a single dimensional * array. * * The keys from each of the 'sub' arrays, ie. the arrays at the * lowest level of the multi array architecture, are preserved. * The multi array argument can be any combination of any level * of single or multi-dimensional arrays, or scalar elements. * @param multi_array - a multi-dimensional array that needs to * have all elements returned as a single * array */ function flatten($multi_array) { $ret = array(); if (is_array($multi_array)) { foreach ($multi_array as $key => $element) { if (is_array($element)) { $ret = ArrayUtility::merge($ret, ArrayUtility::singleDimensionArray($element)); } else { $ret[$key] = $element; } } } else { $ret[] = $multi_array; } return $ret; }