Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
array_flatter
<?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
You can’t perform that action at this time.