PHP code example of rollun-com / rollun-files

1. Go to this page and download the library: Download rollun-com/rollun-files 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/ */

    

rollun-com / rollun-files example snippets


use rollun\files\Csv\CsvFileObjectWithPrKey;

$filename = 'data.csv';
/* 
* id,name,age
* 123,Ivan,25
*/

$csv = new CsvFileObjectWithPrKey(
    $filename,
    ',',
    '"',
    '\\',
    CsvBinaryStrategy::class,
    'id'
);

$row = $csv->getRowById("123"); // 123,Ivan,25

$newRow = [
    "id"   => "456",
    "name" => "John Doe",
    "age"  => "30",
];
$csv->addRow($newRow); // add row to csv
/*
 * id,name,age
 * 123,Ivan,25
 * 456,John Doe,30
 */

$updatedRow = [
    "id"   => "456",
    "name" => "John Smith",
    "age"  => "31",
];
$csv->setRow($updatedRow); // update row with id 456
/*
 * id,name,age
 * 123,Ivan,25
 * 456,John Smith,31
 */