PHPackages                             ckr/csvtools - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. ckr/csvtools

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

ckr/csvtools
============

some functions to process csv data in a lazy way

071PHP

Since May 20Pushed 10y ago1 watchersCompare

[ Source](https://github.com/ckressibucher/csvtools)[ Packagist](https://packagist.org/packages/ckr/csvtools)[ RSS](/packages/ckr-csvtools/feed)WikiDiscussions master Synced today

READMEChangelogDependenciesVersions (1)Used By (0)

Process CSV datasets efficiently
================================

[](#process-csv-datasets-efficiently)

[![Build Status](https://camo.githubusercontent.com/8a01c47cfd52f4bd8cab98e25f8b84738e96c9f0662d4a8c5105194692a6615c/68747470733a2f2f7472617669732d63692e6f72672f636b72657373696275636865722f637376746f6f6c732e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/ckressibucher/csvtools)[![Coverage Status](https://camo.githubusercontent.com/1cf41eef94247247ed05d510ea99978f1c947c139930c8abe95b807fac72ca51/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f636b72657373696275636865722f637376746f6f6c732f62616467652e7376673f6272616e63683d6d6173746572)](https://coveralls.io/github/ckressibucher/csvtools?branch=master)

This is just a collection of functions to process CSV (and other) data structures. The functions are designed in such a way that they can be combined to build processing pipelines. All functions return `Generator`s to ensure that big data sets can be processed without having everything in memory.

The concepts are inspired by lazy functional programming which is very cool :-)

Example (from example.php)
--------------------------

[](#example-from-examplephp)

```
// don't worry, there is also a composer autoloader
// defined
include './csv_functions.php';

use Ckr\CSV as C;

// First, we want to filter the products,
// so we only have the healthy ones...
$filterHealthy = C\buildFilter(
    function (array $row) {
        return $row['is_healthy'] > 5;
    }
);

// We're not interested in the inventory, so
// we select only the other fields
$selectFields = C\buildSelect(
    ['id', 'product', 'price']
);

// Unfortunately, this are not the real prices,
// we also have to add taxes...
$mapAddTaxes = C\buildMap(
    function (array $row) {
        $priceWithTax = floatval($row['price']) * 1.20;
        $row['price_incl_tax'] = $priceWithTax;
        return $row;
    }
);

// Now, lets combine this processing stages to
// a pipeline
$pipeline = C\combineStages(
    $filterHealthy,
    $selectFields,
    $mapAddTaxes
);

// Ehm..., and we also need to have nice string representation
// of the products.
// No problem, we can combine the
// current pipeline -- which is itself a processing stage --
// with another processor
$mapStringField = C\buildMap(
    function (array $row) {
        $str = sprintf(
            '%s (%d) is healthy product and costs only $%s',
            $row['product'],
            intval($row['id']),
            number_format($row['price_incl_tax'], 2)
        );
        $row['as_text'] = $str;
        return $row;
    }
);

// build the new pipeline. Note, that we also need to
// map the "primitive" indexed arrays to associative
// arrays. This is done by the 'toAssoc' function
$newPipeline = C\combineStages(
    'Ckr\\CSV\\toAssoc',
    $pipeline,
    $mapStringField
);

// Now we want to read the csv file, process each row
// and write the result to the output
$input = './example.csv';

// Note that this is still a generator, not the actual
// data. The input file has not yet been read!
$data = $newPipeline(C\readFromFile($input));

// Then we write everything to stdout
$outStream = fopen('php://stdout', 'wb');
C\writeToResource($data, $outStream);
```

###  Health Score

20

—

LowBetter than 13% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity5

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/81e52f2fb24def14cbf90069f298696540f5268e48efff17ab0d53df1ac41137?d=identicon)[ckressibucher](/maintainers/ckressibucher)

---

Top Contributors

[![ckressibucher](https://avatars.githubusercontent.com/u/3111098?v=4)](https://github.com/ckressibucher "ckressibucher (8 commits)")

### Embed Badge

![Health badge](/badges/ckr-csvtools/health.svg)

```
[![Health](https://phpackages.com/badges/ckr-csvtools/health.svg)](https://phpackages.com/packages/ckr-csvtools)
```

###  Alternatives

[coduo/php-humanizer

Humanize values that are readable only for developers

1.7k837.7k21](/packages/coduo-php-humanizer)[amstaffix/pagination

Simple pagination

43292.7k6](/packages/amstaffix-pagination)[trive/module-revo

A Magento 2 module for managing product carousel

103.7k](/packages/trive-module-revo)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
