PHP code example of originphp / csv

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

    

originphp / csv example snippets


use Origin\Csv\Csv;

$csv = Csv::fromArray([
    ['jim','[email protected]'],
    ['tony','[email protected]']
]);


use Origin\Csv\Csv;

$csv = Csv::fromArray([
        ['name'=>'jim','email'=>'[email protected]'],
        ['name'=>'tony','email'=>'[email protected]']
    ],['header'=>true]);


use Origin\Csv\Csv;

$csv = Csv::fromArray([
        ['name'=>'jim','email'=>'[email protected]'],
        ['name'=>'tony','email'=>'[email protected]']
    ],['header'=>['First Name','Email Address']]);


use Origin\Csv\Csv;

$csv = file_get_contents('/path/file.csv');
$data = Csv::toArray($csv);


$data = Csv::toArray($csv,['header'=>true]);

$data = Csv::toArray($csv,['header'=>true,'keys'=>true]);

$data = Csv::toArray($csv,['keys'=>['First Name','Email Address']]);

$rows = Csv::process('/path/to/file.csv',['keys'=>['First Name','Email Address']]);
foreach($rows as $row){
    ... do something
}