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?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire