mardi 11 mai 2021

remove duplicates from laravel array

foreach ($this->data as $row) {
$year = $row[$dataPositions['year']];
$name = $row[$dataPositions['name']];


$foundgames = &$this->foundgames;

    $game = $games->first(function($game, $key) use ($year, $name) {
    if ( $year === $game->year && $game->name === $name ) {
    return true;
    }
});
if ($game) {
    $game->number = $number;
    $game->catalog_name = $name;

    $this->foundgames[] = $game;

    $games = $games->filter(function($gam) use ($game) {
        return $game->id !== $gam->id;
    });
}

}

At this moment I gwr first game correctly and others will go to false, but how I can get all to false if some duplicate matched?



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/33Ds5UU
via IFTTT

Aucun commentaire:

Enregistrer un commentaire