Skip to content

Instantly share code, notes, and snippets.

@sfaut
Created July 30, 2022 10:39
Show Gist options
  • Save sfaut/3008a42de7020c8a2a87ce0554e66535 to your computer and use it in GitHub Desktop.
Save sfaut/3008a42de7020c8a2a87ce0554e66535 to your computer and use it in GitHub Desktop.
<?php
function unflat($record, $separator = '.')
{
$result = [];
foreach ($record as $key => $value) {
$parts = explode($separator, $key);
$count = count($parts);
unset($last); // Nettoyage, pour éviter l'empîlement
$new_field =& $last;
foreach ($parts as $i => $part) {
if ($i < $count - 1) {
$last =& $last[$part];
} else {
$last[$part] = $value;
}
}
$result = array_merge_recursive($result, $new_field);
}
return $result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment