I have an element with title, type, description and so on. I have a DAO that defines all that and functions already created that extract the type for one element only: it’s getById().
How can I loop through all the elements and create groups of them by the same id?
$group = array();
foreach ($announcement as $announcements) {
$announcementType = $this->getById($this->typeId());
}
I should put an "if" here, but I cannot understand how to "create a group for each elements with the same typeId".
2
Answers
It’s not clear why you cycle over $announcements, anyway you can try a solution like this:
You can also try with
array_reduce
(is not an common answer but still an answer):