Skip to content

Instantly share code, notes, and snippets.

@kurozumi
Last active April 3, 2016 03:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kurozumi/972138caaf302638b10986f4c3bc8adf to your computer and use it in GitHub Desktop.
Save kurozumi/972138caaf302638b10986f4c3bc8adf to your computer and use it in GitHub Desktop.
【PHP】League\Csvを拡張してCSVファイルの任意のカラムの重複したデータを削除する方法
<?php
namespace Acme\Csv;
class Reader extends \League\Csv\Reader
{
/**
* @param int $offsetIndex
* @return Generator
*/
public function fetchDeduplicate($offsetIndex=0)
{
$iterator = $this->getQueryIterator();
foreach ($iterator as $row) {
yield $row[$offsetIndex] => implode(",", $row);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment