作者:劈腿年代shui还相信真爱 | 来源:互联网 | 2023-05-18 17:37
I need a way to merge
我需要一个合并的方法。
Array(
[0] => Array
(
[event_id] => 1
[time] => '21:00pm'
[day] => 'Monday'
)
[1] => Array
(
[event_id] => 2
[time] => '18:00pm'
[day] => 'Monday'
)
[2] => Array
(
[event_id] => 3
[time] => '21:00pm'
[day] => 'Tuesday'
)
)
into:
成:
Array (
[0] => Array
(
[event_id] => Array
(
[0] => 1
[1] => 2
)
[time] => Array
(
[0] => '21:00pm'
[1] => '18:00pm'
)
[day] => 'Monday'
)
[1] => Array
(
[event_id] => 3
[time] => '21:00pm'
[day] => 'Tuesday'
)
)
So the new array is grouped by the day key and if the values are different between the merged arrays then the merged value becomes an array.
因此,新的数组按日键分组,如果合并数组中的值不同,则合并后的值就会变成一个数组。
3 个解决方案