Skip to content

Instantly share code, notes, and snippets.

@georgestephanis
Last active February 27, 2016 01:36
Show Gist options
  • Save georgestephanis/20c26b8d467aefc43aa4 to your computer and use it in GitHub Desktop.
Save georgestephanis/20c26b8d467aefc43aa4 to your computer and use it in GitHub Desktop.
<?php
$filename = 'csvdata.csv';
header( 'Content-type: text/plain' );
if ( $data = fopen( $filename, 'r' ) ) {
// Snag the first row as column headers
$cols = fgetcsv( $data );
while ( ( $row = fgetcsv( $data ) ) ) {
// Change it to an associative array!
$row = array_combine( $cols, $row );
// Do whatever.
print_r( $row );
}
// Clean up!
fclose( $data );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment