Skip to content

Instantly share code, notes, and snippets.

@mizner
Created August 7, 2016 22:39
Show Gist options
  • Select an option

  • Save mizner/7d2818b1ddf5d42ccecdc280cd0488ce to your computer and use it in GitHub Desktop.

Select an option

Save mizner/7d2818b1ddf5d42ccecdc280cd0488ce to your computer and use it in GitHub Desktop.
PHP Create & Save CSV to Folder
<?php
$data_array = array (
array ('1','2'),
array ('2','2'),
array ('3','6'),
array ('4','2'),
array ('6','5')
);
$csv = "col1,col2 \n";//Column headers
foreach ($data_array as $record){
$csv.= $record[0].','.$record[1]."\n"; //Append data to csv
}
$csv_handler = fopen ('csvfile.csv','w');
fwrite ($csv_handler,$csv);
fclose ($csv_handler);
echo 'Data saved to csvfile.csv';
@satish-talentedge
Copy link
Copy Markdown

__dfghjk

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment