Теперь вот два массива, которые у меня есть:
first one:
"workingHours": [
{
"opening": "09:30",
"closing": "13:30",
"dayName": "sunday"
},
{
"opening": "",
"closing": "",
"dayName": "monday"
},
{
"opening": "",
"closing": "",
"dayName": "tuesday"
},
{
"opening": "10:30",
"closing": "06:30",
"dayName": "wednesday"
},
{
"opening": "01:00",
"closing": "08:00",
"dayName": "thursday"
},
{
"opening": "",
"closing": "",
"dayName": "friday"
},
{
"opening": "",
"closing": "",
"dayName": "saturday"
},
],
Second one:
"discount": [
{
"from_time": "13:00:00",
"to_time": "14:50:00",
"discount": "20",
"dayName": "wednesday"
},
{
"from_time": "06:13:16",
"to_time": "04:14:11",
"discount": "20",
"dayName": "monday"
},
{
"from_time": "05:10:15",
"to_time": "06:10:17",
"discount": "20",
"dayName": "tuesday"
},
{
"from_time": "06:59:16",
"to_time": "04:19:11",
"discount": "20",
"dayName": "monday"
}
],
Теперь я хочу вывод, подобный этому:
Wanted Output:
"workingHours": {
"opening": "",
"closing": "",
"dayName": "monday"
{
"from_time": "06:13:16",
"to_time": "04:14:11",
"discount": "20",
"dayName": "monday"
},
{
"from_time": "06:59:16",
"to_time": "04:19:11",
"discount": "20",
"dayName": "monday"
}
},
The output that is coming right now:
"workingHours": [
{
"opening": "09:30",
"closing": "13:30",
"dayName": "sunday"
},
{
"0": {
"from_time": "06:13:16",
"to_time": "04:14:11",
"discount": "20",
"dayName": "monday"
},
"1": {
"from_time": "06:59:16",
"to_time": "04:19:11",
"discount": "20",
"dayName": "monday"
},
"opening": "",
"closing": "",
"dayName": "monday"
},
{
"0": {
"from_time": "05:10:15",
"to_time": "06:10:17",
"discount": "20",
"dayName": "tuesday"
},
"opening": "",
"closing": "",
"dayName": "tuesday"
},
{
"0": {
"from_time": "13:00:00",
"to_time": "14:50:00",
"discount": "20",
"dayName": "wednesday"
},
"opening": "10:30",
"closing": "06:30",
"dayName": "wednesday"
},
{
"opening": "01:00",
"closing": "08:00",
"dayName": "thursday"
},
{
"opening": "",
"closing": "",
"dayName": "friday"
},
{
"opening": "",
"closing": "",
"dayName": "saturday"
}
],
Вот мой код:
foreach ($returnDataAns['workingHours'] as $key => $value) {
# code...
foreach ($returnDataAns['discount'] as $key2 => $value2) {
# code...
if ($value['dayName'] == $value2['dayName']) {
# code...
array_push($returnDataAns['workingHours'][$key], $value2);
}
}
}
Есть идеи, как мне это сделать?Я просто хочу удалить эти 0: 1: ключи!