Created
July 30, 2022 10:39
-
-
Save sfaut/3008a42de7020c8a2a87ce0554e66535 to your computer and use it in GitHub Desktop.
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 | |
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