Last active
July 6, 2023 18:04
-
-
Save wgrafael/8a9bb1a963042bc88dac to your computer and use it in GitHub Desktop.
Revisions
-
wgrafael revised this gist
Jan 24, 2017 . 1 changed file with 2 additions and 2 deletions.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 @@ -4,8 +4,8 @@ * Convert array with key in dot notation for multidimensional array * * Example: * Input: [ "name.firstname" => "Rafael", "name.lastname" => "Dantas", "a.b.c" => "d" ] * Output: [ "name" => [ "firstname" => "Rafael", "lastname" => "Dantas" ], "a" => [ "b" => [ "c" => "d" ] ] * * @param $array Array with key in dot notation * @return Array array multidimensional -
wgrafael revised this gist
Jan 24, 2017 . 1 changed file with 7 additions and 1 deletion.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 @@ -1,8 +1,14 @@ <?php /** * Convert array with key in dot notation for multidimensional array * * Example: * Input: [ "name.firstname" => "Rafael", "name.lastname" => "Dantas" ] * Output: [ "name" => [ "firstname" => "Rafael", "lastname" => "Dantas" ] ] * * @param $array Array with key in dot notation * @return Array array multidimensional * @author Rafael Dantas */ function convertDotToArray($array) { -
wgrafael revised this gist
Jan 7, 2016 . 1 changed file with 2 additions and 0 deletions.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 @@ -1,3 +1,5 @@ <?php /** * Convert dot notation for multidimensional array * -
wgrafael renamed this gist
Jan 7, 2016 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
wgrafael created this gist
Jan 7, 2016 .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,24 @@ /** * Convert dot notation for multidimensional array * * @author Rafael Dantas */ function convertDotToArray($array) { $newArray = array(); foreach($array as $key => $value) { $dots = explode(".", $key); if(count($dots) > 1) { $last = &$newArray[ $dots[0] ]; foreach($dots as $k => $dot) { if($k == 0) continue; $last = &$last[$dot]; } $last = $value; } else { $newArray[$key] = $value; } } return $newArray; }