by
12k 31
0
7
7,227
3
Top 1% !
Popular
Famous
Pearl of Wisdom
Tagged
Specified
OpenSource
Popularity: 843rd place
Created
Modified Dec 18, 2013

Published on:

Architecturex86_64
LanguagePHP
LicenseMIT_X11
OSWindows
Windows VersionWindows8

Csv to array PHP

How to convert a csv file into an array with header in PHP
Copy Embed Code
<iframe id="embedFrame" style="width:600px; height:300px;"
src="https://www.snip2code.com/Embed/12431/Csv-to-array-PHP?startLine=0"></iframe>
Click on the embed code to copy it into your clipboard Width Height
Leave empty to retrieve all the content Start End
$filename="filename.csv"; $delimiter=","; $rowlenght=500 if(!file_exists($filename) || !is_readable($filename)) return FALSE; $header = NULL; $data = array(); if (($handle = fopen($filename, "r")) !== FALSE) { while (($row = fgetcsv($handle, $rowlenght, $delimiter)) !== FALSE) { if(!$header) { $header = $row; } else {$data[] = array_combine($header, $row); } } fclose($handle); } // read array data foreach($data as $obj){ $status = $obj->ColumnName; print "$status"; }
If you want to be updated about similar snippets, Sign in and follow our Channels

blog comments powered by Disqus