PHP code example of colbygatte / smart-csv

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

    

colbygatte / smart-csv example snippets



$csv = csv(['name', 'age']);
$csv->append(['Mark', 28], ['Colby', 26])  // Multiple rows can be passed at once
    ->write('info.csv');


foreach (csv_sip('people.csv') as $row) {
    echo $row->name; 
}


$csv = csv_slurp('people.csv');
foreach ($csv as $row) {
    echo $row->age;
}


$writer = csv_writer('data.csv', ['time', 'cost']);
$writer->append(['4pm', '$100'], ['1am', '$14']); // Append automatically writes each row


$alter = csv_alter('people.csv', 'altered-people.csv');
foreach ($alter as $row) {
    // Change stuff
    $row->name = strtoupper($row->name);
    // If the delete() method is called on the row, it will not be 


$csv = csv_sip('people.csv')->makeGroup('attributes', 'attribute', ['value', 'note']);
foreach ($csv as $row) {
    print_r($row->groups()->attributes);
}