I want to create an overview of the first dates of every event. So the event-title must be unique. My idea was to create a helper-function where I loop over the result of my query and check the title of every item. To make sure every title passes only once, I want to push the title into an array ($checklist). If it does not exist, I add that item to the result-array. If it does, just continue to the next item.
I always get the error:
in_array() expects parameter 2 to be array, integer given
This is my code:
function showFirstEvenst($collection) {
$checklist = array();
$result = array();
foreach ($collection as $item) {
$title = strtolower($item['events']['title']);
if (!in_array($title, $checklist)) {
$checklist = array_push($checklist, $title);
$result = array_push($result, $item);
}
}
return $result;
}
I already tried to cast $checklist and $result as array in the foreach loop but without result.
What do I need to change?