ziyodulloxon / simple-csv
Simple CSV reader/writer
dev-master
2025-04-03 07:25 UTC
Requires
- php: ^8.0
Requires (Dev)
- phpunit/phpunit: ^9.0
This package is auto-updated.
Last update: 2025-05-03 07:36:58 UTC
README
Basic Usage
$reader = new \Ziyodulloxon\SimpleCsv\Reader("./path/to/file.csv"); $rows = $reader->read(); foreach ($rows as $row) { var_dump($row); }
Output:
[ 0 => 111, 1 => "+79991234567", 2 => "John Smith", ], [ 0 => 112, 1 => "+79881234568", 2 => "Jane Doe", ], [ 0 => 49329, 1 => "+79771234569", 2 => "Walter White", ]
Using associateWithHeaders()
to Use Headers as Keys
$reader = new \Ziyodulloxon\SimpleCsv\Reader("./path/to/file.csv"); $rows = $reader->associateWithHeaders()->read(); foreach ($rows as $row) { var_dump($row); }
Output:
[ "id_client" => 111, "phone" => "+79991234567", "name" => "John Smith", ], [ "id_client" => 112, "phone" => "+79881234568", "name" => "Jane Doe", ], [ "id_client" => 49329, "phone" => "+79771234569", "name" => "Walter White", ]
Using batchRead()
for Large Files
$reader = new \Ziyodulloxon\SimpleCsv\Reader("./path/to/file.csv"); //$iterable is an instance of \Generator $iterable = $reader->associateWithHeaders()->batchRead(1); foreach ($iterable as $item) { var_dump($item); }
Output:
Same as above, but with lower memory usage.