PHPackages                             g105b/phpcsv - 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. [Database &amp; ORM](/categories/database)
4. /
5. g105b/phpcsv

ActiveLibrary[Database &amp; ORM](/categories/database)

g105b/phpcsv
============

Wraps SplFileObject's CSV capabilities with a more human approach

v1.0.3(9y ago)117.9kMITPHP

Since Feb 10Pushed 9y ago1 watchersCompare

[ Source](https://github.com/g105b/phpcsv)[ Packagist](https://packagist.org/packages/g105b/phpcsv)[ RSS](/packages/g105b-phpcsv/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (1)Versions (18)Used By (0)

phpcsv
======

[](#phpcsv)

Wraps SplFileObject's CSV capabilities with a more human approach

[![Build status](https://camo.githubusercontent.com/6080de3f64e850235d75c4ebc5d35c3750ee1cb25526154dcc9dd80f1604b42b/68747470733a2f2f696d672e736869656c64732e696f2f636972636c6563692f70726f6a6563742f67313035622f7068706373762e7376673f7374796c653d666c61742d737175617265)](https://circleci.com/gh/g105b/phpcsv)[![Composer Version](https://camo.githubusercontent.com/4411665c08a23c57decf6835850793ceb4e24544def2f31978ac25fb640a7c60/687474703a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f67313035622f7068706373762e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/g105b/phpcsv)[![Download Stats](https://camo.githubusercontent.com/bb3ca8597702beb87e48d542076bc41e528a20c68ce7a9590b45b9b3c17509a8/687474703a2f2f696d672e736869656c64732e696f2f7061636b61676973742f646d2f67313035622f7068706373762e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/g105b/phpcsv)

Features at a glance
--------------------

[](#features-at-a-glance)

- Enhances PHP's SplFileObject, a memory-efficient file stream.
- Simple filtering of rows by field value (`getAllBy("fieldName", "fieldValue")`).
- Results are associative arrays, the indices are the CSV header names.
- Iterate over CSV files by row.
- Reference CSV rows by row number.
- Reference CSV rows by ID value.

Screenshot in action
--------------------

[](#screenshot-in-action)

[![Screenshot of phpcsv](https://raw.githubusercontent.com/g105b/phpcsv/master/screenshot.png)](https://raw.githubusercontent.com/g105b/phpcsv/master/screenshot.png)

Usage
-----

[](#usage)

Here are a few use cases to best show the functionality of the library. For a complete guide, [visit the documentation](https://github.com/g105b/phpcsv/wiki).

### Add rows

[](#add-rows)

```
$csv = new Csv("/path/to/file.csv");
$csv->add([
    "firstName" => "Alan",
    "lastName" => "Statham",
    "Job Title" => "Consultant Radiologist",
]);
$csv->add([
    "firstName" => "Caroline",
    "lastName" => "Todd",
    "Job Title" => "Surgical Registrar",
]);
```

### Get rows

[](#get-rows)

```
$csv = new Csv("/path/to/file.csv");
$resultRows = $csv->getAllBy("gender", "F"); // array of all matching rows.
$firstRow = $csv->getBy("gender", "F"); // single row, first matching.
```

### Iterate over rows

[](#iterate-over-rows)

```
$csv = new Csv("/path/to/file.csv");

foreach ($csv as $rowNumber => $row) {
    // $row is an associative array with CSV headers as each key.
    // $rowNumber starts from 1 (ignoring header row).
}
```

### Update row

[](#update-row)

```
$csv = new Csv("/path/to/file.csv");
$row = $csv->getBy("email", "barack@whitehouse.gov");

// Update the matching row with provided fields, keeping any
// existing field data on the existing row.
$csv->update($row, [
    "dateOfBirth" => "1961-08-04",
]);
```

### Delete row

[](#delete-row)

```
$csv = new Csv("/path/to/file.csv");

// Delete a row by its index.
$csv->deleteRow(22);
```

Future feature ideas
--------------------

[](#future-feature-ideas)

- Requesting only certain fields in result (v2)
- Type handling (v3)
- Sorting (v4)
- Faster retrieval of indexed rows (v4)

###  Health Score

34

—

LowBetter than 77% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity21

Limited adoption so far

Community4

Small or concentrated contributor base

Maturity72

Established project with proven stability

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.

###  Release Activity

Cadence

Every ~36 days

Recently: every ~113 days

Total

14

Last Release

3636d ago

Major Versions

v0.5.1 → v1.0.02015-05-11

### Community

Maintainers

![](https://www.gravatar.com/avatar/9e42344b91ce4b91ab57875969f67a0a6a48de570a08bc65d673b06b72fd3a3f?d=identicon)[g105b](/maintainers/g105b)

---

Tags

databaseexportcsvfilterimportreadwriteiterate

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/g105b-phpcsv/health.svg)

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

###  Alternatives

[league/csv

CSV data manipulation made easy in PHP

3.5k166.1M646](/packages/league-csv)[ddeboer/data-import

Import data from, and export data to, a range of file formats and media

5604.3M9](/packages/ddeboer-data-import)[mpyw/laravel-cached-database-stickiness

Guarantee database stickiness over the same user's consecutive requests

83316.8k](/packages/mpyw-laravel-cached-database-stickiness)[shuchkin/simplecsv

Parse and retrieve data from CSV files. Export data to CSV.

5192.4k](/packages/shuchkin-simplecsv)[rah/danpu

Zero-dependency MySQL dump library for easily exporting and importing databases

64401.8k10](/packages/rah-danpu)[bakame/html-table

convert html table into a PHP data structure

113.0k](/packages/bakame-html-table)

PHPackages © 2026

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