0, '2' => 0, '3' => 0 ]; foreach ($participantList as $participant) { if ( $participant->essgewohnheit !== $eatingHabit ) { continue; } $anreise = \DateTime::createFromFormat( 'Y-m-d', $participant->anreise ); $abreise = \DateTime::createFromFormat( 'Y-m-d', $participant->abreise ); if ( $anreise->getTimestamp() < $date->getTimestamp() && $abreise->getTimestamp() > $date->getTimestamp() ) { $participantCount['1']++; $participantCount['2']++; $participantCount['3']++; } elseif ( $anreise->getTimestamp() == $date->getTimestamp() ) { // Anreisetag if ( $participant->anreise_essen == 3 ) { $participantCount['1']++; $participantCount['2']++; $participantCount['3']++; } elseif ( $participant->anreise_essen == 2 ) { $participantCount['2']++; $participantCount['3']++; } elseif ( $participant->anreise_essen == 1 ) { $participantCount['3']++; } } elseif ( $abreise->getTimestamp() == $date->getTimestamp() ) { // Abreisetag if ( $participant->abreise_essen == 3 ) { $participantCount['1']++; $participantCount['2']++; $participantCount['3']++; } elseif ( $participant->abreise_essen == 2 ) { $participantCount['1']++; $participantCount['2']++; } elseif ( $participant->abreise_essen == 1 ) { $participantCount['1']++; } } } return $participantCount; } }