$listと$list2の2 つの配列があります。
$リスト:
Array
(
[0] => Array
(
[team] => 14
[team_points] => 3
[team_occurrences] => 2
)
[1] => Array
(
[team] => 1
[team_points] => 3
[team_occurrences] => 2
)
[2] => Array
(
[team] => 5
[team_points] => 1
[team_occurrences] => 1
)
[3] => Array
(
[team] => 13
[team_points] => 1
[team_occurrences] => 1
)
[4] => Array
(
[team] => 7
[team_points] => 0
[team_occurrences] => 1
)
[5] => Array
(
[team] => 2
[team_points] => 0
[team_occurrences] => 3
)
)
$list2:
Array
(
[0] => Array
(
[team] => 20
[team_points] => 7
[team_occurrences] => 3
)
[1] => Array
(
[team] => 10
[team_points] => 3
[team_occurrences] => 1
)
[2] => Array
(
[team] => 14
[team_points] => 3
[team_occurrences] => 1
)
[3] => Array
(
[team] => 13
[team_points] => 3
[team_occurrences] => 1
)
[4] => Array
(
[team] => 19
[team_points] => 3
[team_occurrences] => 1
)
[5] => Array
(
[team] => 17
[team_points] => 1
[team_occurrences] => 1
)
[6] => Array
(
[team] => 11
[team_points] => 0
[team_occurrences] => 1
)
[7] => Array
(
[team] => 15
[team_points] => 0
[team_occurrences] => 1
)
)
ご覧のとおり、列は両方の配列で同じです (team、team_points、team_occurrences)
ここで、これら 2 つの配列を$list_allという配列にマージしたいと思います。
マージの問題は、私が試した標準のマージです
array_merge($list,$list2);
それらを一緒に追加するだけです。
ただし、必要なのは同じチームをカウントすることです。たとえば、 [team] => 14と[team] => 13は両方の配列 ($list と $list2) にあるため、 $list からteam_points列の値を合計する必要があります。チームが同一の場合、$ list2 のteam_points列の値を使用します。team_occurrences列についても同じです。
だから例えば
新しい配列は次のようにはなりません。
Array
(
[0] => Array // from $list
(
[team] => 14
[team_points] => 3
[team_occurrences] => 2
)
[1] => Array // from $list2
(
[team] => 14
[team_points] => 3
[team_occurrences] => 1
)
[3] => Array // from $list
(
[team] => 13
[team_points] => 1
[team_occurrences] => 1
)
[4] => Array // from $list2
(
[team] => 13
[team_points] => 3
[team_occurrences] => 1
)
しかし、私はそれが次のようになる必要があります:
Array
(
[0] => Array
(
[team] => 14
[team_points] => 6
[team_occurrences] => 3
)
[1] => Array
(
[team] => 13
[team_points] => 4
[team_occurrences] => 2
)
マージ後、usort() または team_points DESC によるより良い関数 (最高値から最低値へ) を使用して結果配列をソートしたいと思います。
アドバイスをよろしくお願いします。