PHP code example of alva / csv-each

1. Go to this page and download the library: Download alva/csv-each 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/ */

    

alva / csv-each example snippets


use Alva\CsvEach\Iterate;

foreach ((new Iterate($pathToFile))->each(Iterate::TYPE_TEXT) as $lineNumber => $line) {
    echo '[' . $lineNumber . '] ' . $line . PHP_EOL;
}

use Alva\CsvEach\Iterate;

foreach ((new Iterate($pathToFile))->setDelimiter(',')->each(Iterate::TYPE_ARRAY) as $lineNumber => $line) {
    echo '[' . $lineNumber . '] ' . PHP_EOL;
    print_r($line);
}

use Alva\CsvEach\Iterate;

foreach ((new Iterate($pathToFile))->each(Iterate::TYPE_BINARY, 5) as $lineNumber => $line) {
    echo '[' . $lineNumber . '] ' . $line . PHP_EOL;
}