<?php
$basketballlLovers = ["ARDI", "RESKA", "SISKA"];
$soccerLovers = ["SISKA", "BUDI", "DAMIAN"];
$swimmingLovers = ["DAMIAN", "RESKA", "ANITA"];
function getStudentWhoLoveBasketballAndSoccer(array $basketballlLovers, array $soccerLovers): array
{
return array_intersect($basketballlLovers, $soccerLovers);
}
function getStudentWhoLoveBasketballOrSwimming(array $basketballlLovers, array $swimmingLovers): array
{
return array_unique(array_merge($basketballlLovers, $swimmingLovers));
}
function getStudentWhoOnlyLoveSoccer(array $basketballlLovers, array $soccerLovers, array $swimmingLovers): array
{
$compareWithBasketball = array_diff($soccerLovers, $basketballlLovers);
$compareWithSwimming = array_diff($soccerLovers, $swimmingLovers);
return array_intersect($compareWithBasketball, $compareWithSwimming);
}
// love basketball and soccer
print_r(getStudentWhoLoveBasketballAndSoccer($basketballlLovers, $soccerLovers));
// love basketball or swimming
print_r(getStudentWhoLoveBasketballOrSwimming($basketballlLovers, $swimmingLovers));
// love soccer only
print_r(getStudentWhoOnlyLoveSoccer($basketballlLovers, $soccerLovers, $swimmingLovers));