Recently I am working on a project that categorises 'Superheros' and 'Supervillains' based on their 'Franchaise' and origin of 'Superpower'. I want to fetch data from database as as Array #1 and displays them as Array #2 in php.
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
)
)
Array #1 elements have to be grouped based on their 'Franchise' and count how many of them are 'Inherent' or 'Acquired' in terms of 'Superpower'.
Array #2
Array
(
[DC Comics] => Array
(
[Inherent] => 1
[Acquired] => 1
)
[Marvel] => Array
(
[Inherent] => 1
[Acquired] => 2
)
)