<?php
/**
 * Praktikum DBWT. Autoren:
 * Şafak, Hazinedar, 3108590
 * Robert, Joel, 3672729
 */

function missingYear($famousMeals){
    $years = [];
    $winneryears = [];
    $ergebniss = [];
    for ($i = 0;$i <= 23; $i++){
        $years[] = 2000+$i;
    }

    foreach ($famousMeals as $meal){
        if(gettype($meal["winner"])== "array"){
            foreach ($meal["winner"]as $year){
                $winneryears[] = $year;
            }
        }else{
            $winneryears[] = $year;
        }
    }

    foreach ($years as $year){
        $a=0;
        foreach ($winneryears as $winners){
            if ($year == $winners){
                $a = 1;
                break;
            }
        }
        if($a==0){
            $ergebniss[]=$year;
        }
    }
    echo var_dump($ergebniss);
}

$famousMeals = [
    1 => ['name' => 'Currywurst mit Pommes',
        'winner' => [2001, 2003, 2007, 2010, 2020]],
    2 => ['name' => 'Hähnchencrossies mit Paprikareis',
        'winner' => [2002, 2004, 2008]],
    3 => ['name' => 'Spaghetti Bolognese',
        'winner' => [2011, 2012, 2017]],
    4 => ['name' => 'Jägerschnitzel mit Pommes',
        'winner' => 2019]
];
    echo "<ol>";
    foreach ($famousMeals as $meal){
        echo "<li>". $meal['name']."<br>";
        if(gettype($meal["winner"])== "array"){
            foreach ($meal["winner"]as $year){
                $dump[] = $year;
            }
        }else{
            $dump[] = $year;
        }
        echo implode( ', ', $dump);
        $dump = null;
        echo "</li><br>";
    }
    echo "</ol>";
    missingYear($famousMeals);
?>