最近,我正在開發一個項目,根據他們的'Franchaise'和'Superpower'的來源對'Superheros'和'Supervillains'進行分類。我想從數據庫中獲取數據,如數組#1,並將它們顯示爲數組#2在PHP中。在php和count數據中對數組進行分組
Array #1
Array
(
[0] => Array
(
[id] => 101
[Name] => Superman
[Franchise] => DC Comics
[Superpower] => Inherent
)
[1] => Array
(
[id] => 908
[Name] => Batman
[Franchise] => DC Comics
[Superpower] => Acquired
)
[2] => Array
(
[id] => 228
[Name] => Wolverine
[Franchise] => Marvel
[Superpower] => Acquired
)
[3] => Array
(
[id] => 158
[Name] => Iron Man
[Franchise] => Marvel
[Superpower] => Acquired
)
[4] => Array
(
[id] => 978
[Name] => Thor
[Franchise] => Marvel
[Superpower] => Inherent
)
)
陣列#1的元素必須分組基於他們的「特權」,並指望有多少人是「固有」或在「超級大國」術語「後天」。
Array #2
Array
(
[DC Comics] => Array
(
[Inherent] => 1
[Acquired] => 1
)
[Marvel] => Array
(
[Inherent] => 1
[Acquired] => 2
)
)
哪裏是你的代碼的企圖? – MikeBergerUS
托爾沒有繼承他的超級大國。他被給了Mjolnir。 – Goose
你想要算什麼? 數組或相同鍵的數組? –