Skip to content

billisonline/csv-query

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CSV Query

This library lets you "query" CSV files as fluent collection objects. Each row is encapsulated into a row object which makes cells accessible by their column name. Rows are then bundled into an Illuminate LazyCollection, exposing functionality like where, filter, map, reduce, count and more. (Illuminate is the Laravel support library, but Laravel is not required.)

All content is lazy-loaded and the entire CSV is never read into memory, making this library fast and suitable for use with very large CSV files.

Examples

Iterate through rows and access columns by name:

<?php

foreach ($csv->iterateRows() as $row) {
    $firstName = $row['name/first'];
    $lastName = $row->get('name/last');
    $lastName = $row->get('name/middle', '--'); // Returns "--" by default if there is no "name/middle" column
}

Get a collection of rows and use functions like where and count:

<?php

$seniorsCount = $csv->rows()->where('age', '>=', 65)->count();

Consolidate rows with functions like pluck:

<?php

$lastNames = $csv->rows()->pluck('name/last');

Use aggregate functions like average:

<?php

$averageAge = $csv->rows()->average('age');

License

MIT

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages