Skip to content

Instantly share code, notes, and snippets.

@Werninator
Created September 12, 2018 09:34
Show Gist options
  • Select an option

  • Save Werninator/fd66e9b9e17069da4ab385e07c74d9fa to your computer and use it in GitHub Desktop.

Select an option

Save Werninator/fd66e9b9e17069da4ab385e07c74d9fa to your computer and use it in GitHub Desktop.

Revisions

  1. Patrick Werner created this gist Sep 12, 2018.
    14 changes: 14 additions & 0 deletions csv-to-assoc.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,14 @@
    <?php

    // modified version of https://steindom.com/articles/shortest-php-code-convert-csv-associative-array

    function str_getcsv_semicolons($input) {
    return str_getcsv($input, ';');
    }

    $rows = array_map('str_getcsv_semicolons', file($filedir));
    $header = array_shift($rows);
    $data = [];

    foreach ($rows as $row)
    $data[] = array_combine($header, $row);