'PHP - Compare values in an array of objects
I have an array of objects and i should compare which ones have two equal values.
The real case is this: i have a series of events, each of which has a date, a title and a speaker. Many of these events have multiple speakers and unfortunately i find a DB where they have decided to duplicate the event for each speaker.
So I have many events with the same date and the same title but different speaker. I would like to print only one event, with the list of speakers.
Here is a concrete example that is perhaps more intuitive. Starting situation:
Array (
[0] => stdClass Object (
[id] => 193
[date] => 2022-05-10
[title] => Lezione 1
[speaker] => Andrea
[1] => stdClass Object (
[id] => 194
[date] => 2022-05-10
[title] => Lezione 1
[speaker] => Giorgio
[2] => stdClass Object (
[id] => 195
[date] => 2022-05-10
[title] => Lezione 1
[speaker] => Giorgio
[3] => stdClass Object (
[id] => 196
[date] => 2022-05-11
[title] => Lezione 2
[speaker] => Giorgio
[4] => stdClass Object (
[id] => 197
[date] => 2022-05-11
[title] => Lezione 2
[speaker] => Giorgio
The result I would like to obtain is:
10 May 22 - Lezione 1 - Speaker: Andrea, Giorgio
11 May 22 - Lezione 2 - Speaker: Giorgio
I tried to use array_unique function but i can't get the desired result. Do you have any suggestions?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
