Skip to content

Instantly share code, notes, and snippets.

@isaqueprofeta
Last active April 17, 2020 18:25
Show Gist options
  • Save isaqueprofeta/533f5e82a673ff7200655c35729b0066 to your computer and use it in GitHub Desktop.
Save isaqueprofeta/533f5e82a673ff7200655c35729b0066 to your computer and use it in GitHub Desktop.
<?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