Created
June 21, 2011 13:52
-
-
Save GromNaN/1037894 to your computer and use it in GitHub Desktop.
array_flatter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Convert a multi-dimensions array to a 1 flat array. | |
* | |
* @param array $array | |
* @param string $separator | |
* @param string $prefix | |
* @return array | |
*/ | |
function array_flatter($array, $separator = '/', $prefix = '') { | |
$flat = array(); | |
foreach($array as $key => $value) { | |
if(is_array($value)) { | |
$flat = array_merge($flat, array_flatter($value, $separator, $prefix.$key.$separator)); | |
} else { | |
$flat[$prefix.$key] = $value; | |
} | |
} | |
return $flat; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment