PHP code example of mhndev / csv

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

    

mhndev / csv example snippets



use mhndev\csv\Csv;

$csv = new Csv();
$sampleArray = [[1,2,3,4,5],[6,7,8,9,10]];
$filename ="/path/to/test.csv";
$csv->arrayToCsv($sampleArray, $filename);
$resultArrayIterator = $csv->csvToArrayUsingGenerator($filename);




$csv = new Csv();
$sampleArray = [[1,2,3,4,5],[6,7,8,9,10],[11,12,13,14,15]];
$filename ="/path/to/test.csv";
$csv->arrayToCsv($sampleArray, $filename);
$csv->deleteOneLineById($filename, 1);


$csv = new Csv();
$sampleArray = [[1,2,3,4,5],[6,7,8,9,10],[6,'hamid',8,9,'majid']];
$filename ="/path/to/test.csv";
$csv->arrayToCsv($sampleArray, $filename);
$csv->updateLineBy($filename, [2=>8] , [11,12,13,14,15]);