Development

David Carr

Export to CSV

Today I've released a new PHP package for exporting array data to a CSV file. Often data needs exporting from a database into CSV files. 

To install the package import it with composer:

composer require daveismyname/exportcsv

Then to use it import the namespace

use Daveismyname\ExportCsv\ExportCsv;

To export the data the following is required

//set filename
$filename = 'test.csv';

//set column names
$headerFields = array('First Name', 'Last Name', 'Company', 'Created');

//create array
$records = [];

//loop through data and add to array
foreach($contacts as $row) {
    $records[] = array(
        $row->firstName, 
        $row->lastName, 
        $row->companyName, 
        $row->created_at
    );
}

//send params to csv 
new csv($records, $filename, $headerFields);

More details can be found at https://github.com/daveismyname/exportcsv

Domains are often purchased from multiple providers, keeping track of where a domain is and its DNS settings can be tricky. Domain Mapper solves this by listing all your domains in one place. View your DNS settings and receive reminders to renew your domains. Try it today.

Support my work by donating with PayPal.

Subscribe to my newsletter

Subscribe and get my books and product announcements.

© 2009 - 2021 DC Blog. All code MIT license. All rights reserved.