所以我在给定的输入和输出中尝试了一些东西,假设Days只有一个值,对吗?
$schedules =
[
[
'TIME' =>
[
[
"FROM" => "10:00",
"TO" => "20:00"
]
],
'DAYS' => [5]
],
[
'TIME' =>
[
[
"FROM" => "22:00",
"TO" => "00:00"
]
],
'DAYS' => [5]
]
];
$hashmap = [];
foreach ($schedules as $schedule) {
$days = $schedule['DAYS'][0];
if (!isset($hashmap[$days])) {
$hashmap[$days] = $schedule;
} else {
$hashmap[$days]['TIME'] = array_merge($hashmap[$days]['TIME'], $schedule['TIME']);
}
}
$hashmap = array_values($hashmap);
希望这能有所帮助