CSV to array

function csv_to_array($filename, $delimiter) {
    ini_set('auto_detect_line_endings', true);

    if(!file_exists($filename) || !is_readable($filename)) {
        return FALSE;
    }

    $header = NULL;
    $data = array();
    if (($handle = fopen($filename, 'r')) !== FALSE)   {
        while (($row = fgetcsv($handle, $delimiter)) !== FALSE)
        {
            if(!$header) {
                $header = $row;
            } else {
                $data[] = array_combine($header, $row);
            }
        }
        fclose($handle);
    }
    return $data;
}
SHARE
Previous articleList all active plugins
Next articlePHP Math functions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

*