mirror of
https://github.com/parsecsv/parsecsv-for-php.git
synced 2026-02-19 08:36:39 +00:00
Added example for writing CSV files to better document heading property
Fixes #161
This commit is contained in:
27
examples/save_to_file_without_header_row.php
Normal file
27
examples/save_to_file_without_header_row.php
Normal file
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
|
||||
# include parseCSV class.
|
||||
require __DIR__ . '/../vendor/autoload.php';
|
||||
|
||||
use ParseCsv\Csv;
|
||||
|
||||
|
||||
# Create new parseCSV object.
|
||||
$csv = new Csv();
|
||||
|
||||
# When saving, don't write the header row:
|
||||
$csv->heading = false;
|
||||
|
||||
# Specify which columns to write, and in which order.
|
||||
# We won't output the 'Awesome' column this time.
|
||||
$csv->titles = ['Age', 'Name'];
|
||||
|
||||
# Data to write:
|
||||
$csv->data = [
|
||||
0 => ['Name' => 'Anne', 'Age' => 45, 'Awesome' => true],
|
||||
1 => ['Name' => 'John', 'Age' => 44, 'Awesome' => false],
|
||||
];
|
||||
|
||||
# Then we save the file to the file system:
|
||||
$csv->save('people.csv');
|
||||
Reference in New Issue
Block a user