PHP code example of dutchcodingcompany / csv-collection

1. Go to this page and download the library: Download dutchcodingcompany/csv-collection library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

dutchcodingcompany / csv-collection example snippets

 
CsvCollection::make();

use DutchCodingCompany\CsvCollection\CsvCollection;

CsvCollection::make()
    ->open('path/to/file.csv')
    ->count();

use DutchCodingCompany\CsvCollection\CsvCollection;

CsvCollection::make(static function () {
    yield [
        'key' => 'value',
    ];
})
    ->save('path/to/file.csv');

use DutchCodingCompany\CsvCollection\CsvCollection;

CsvCollection::make(static function () {
    $models = Model::query()->lazy();
    
    foreach ($models as $model){
        yield $model->only([
            'id',
            //
        ]);
    }
})
    ->save('path/to/file.csv');

// Without header
[
    0 => 'John',
    1 => 'Doe',
]

// With header
[
    'first_name' => 'John',
    'last_name' => 'Doe',
]

CsvCollection::detectDelimiter($path);