PHP code example of daniel-griffiths / csv

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

    

daniel-griffiths / csv example snippets




anielGriffiths\CSV;

// Convert a CSV file to a array
$rows = CSV::fromFile(__DIR__.'/file.csv');

// Convert an array to a CSV string
$csvString = CSV::fromArray([
    [
        'animal' => 'Dog',
        'name' => 'Patch',
    ]
])->toString();

// Convert an array to a CSV and download it
CSV::fromArray([
    [
        'animal' => 'Dog',
        'name' => 'Patch',
    ]
])->download('file.csv');

// Convert an array to a CSV and write it to a file
CSV::fromArray([
    [
        'animal' => 'Dog',
        'name' => 'Patch',
    ]
])->toFile('file.csv');