Last active
April 17, 2020 18:25
-
-
Save isaqueprofeta/533f5e82a673ff7200655c35729b0066 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 | |
$in = <<<'JSON' | |
[ | |
{ | |
"Date": "2014-12-01", | |
"StartTime": "10:00", | |
"EndTime": "16:00" | |
}, | |
{ | |
"Date": "2014-12-02", | |
"StartTime": "12:00", | |
"EndTime": "18:00" | |
}, | |
{ | |
"Date": "2014-12-03", | |
"StartTime": "10:00", | |
"EndTime": "20:00" | |
}, | |
{ | |
"Date": "2014-12-03", | |
"StartTime": "12:00", | |
"EndTime": "20:00" | |
} | |
] | |
JSON; | |
$data = json_decode($in, true); | |
$out = []; | |
foreach($data as $element) { | |
$out[$element['Date']][] = ['StartTime' => $element['StartTime'], 'EndTime' => $element['EndTime']]; | |
} | |
var_dump(json_encode($out, JSON_PRETTY_PRINT)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment