数组a
Array
(
[0] => Array
(
[member_id] => 6
[sorting] => 0
[total] => 1
)
[1] => Array
(
[member_id] => 7
[sorting] => 1
[total] => 2
)
)
数组b
Array
(
[0] => Array
(
[member_id] => 2
[total] => 3
)
[1] => Array
(
[member_id] => 6
[total] => 1
)
[2] => Array
(
[member_id] => 7
[total] => 2
)
)
问题:以上数据我尝试循环数组并存储到新数组中,如下所示(最终数据)。首先,如果第二个数组缺少成员数据,那么我需要从第一个数组中获取成员数据并将其存储到新数组中。除此之外,如果缺少排序,我需要从第一个数组中获取排序值。最后,我能够很好地获取所有数据,但最后存储到其中的值将会重复。任何人都可以帮忙:(?我的逻辑停留在这里。
我的代码返回
Array
(
[0] => Array
(
[member_id] => 6
[total] => 1
[sorting] => 0
)
[1] => Array
(
[member_id] => 7
[total] => 2
[sorting] => 1
)
[2] => Array
(
[member_id] => 7
[total] => 2
[sorting] =>
)
)
最终数据应该是:
Array
(
[0] => Array
(
[member_id] => 6
[total] => 1
[sorting] => 0
)
[1] => Array
(
[member_id] => 7
[total] => 2
[sorting] => 1
)
[2] => Array
(
[member_id] => 2
[total] => 3
[sorting] => 2
)
)
代码: https: //3v4l.org/WBLCC
慕娘9325324
梦里花落0921