Created
December 29, 2021 13:01
-
-
Save maxcelos/6f1b8acd45d97068bceb4c5d4f5f61da to your computer and use it in GitHub Desktop.
Revisions
-
maxcelos created this gist
Dec 29, 2021 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,20 @@ ```php flatten(array $array, $keyPrefix = ''): array { $return = []; foreach ($array as $key => $value) { $key = trim($keyPrefix . '_' . $key, '_'); if (is_array($value)){ $return = array_merge($return, flatten($value, $key)); } else { $return[$key] = $value; } } return $return; } ``` 