bluefrg/parsecsv

Extend PHP's native CSV parsing from the SplFileObject class but provide features to use the first row's values as keys on the remaining rows.

2.0.0 2024-03-21 21:13 UTC

This package is auto-updated.

Last update: 2024-04-21 21:21:32 UTC


README

Extend PHP's native CSV parsing from the SplFileObject class but provide features to use the first row's values as keys on the remaining rows.

There are other libraries which accomplish the similar thing, but they are memory inefficient and rely on their own (sometimes buggy) parsing implementation.

<?php
$oCsv = new ParseCsv('users.csv');
$oCsv->firstRowHeader();

foreach($oCsv as $aRow) {
    print_r($aRow);
}

Given the example users.csv file:

id,firstName
11,Billy

The resulting output will be:

Array
(
    [id] => 11
    [firstName] => Billy
)

Install

$ composer require bluefrg/parsecsv:dev-master