You are here

public function LdapTestFunctions::parseCsv in Lightweight Directory Access Protocol (LDAP) 7.2

Same name and namespace in other branches
  1. 8.2 ldap_test/LdapTestFunctions.class.php \LdapTestFunctions::parseCsv()
1 call to LdapTestFunctions::parseCsv()
LdapTestFunctions::getCsvLdapData in ldap_test/LdapTestFunctions.class.php

File

ldap_test/LdapTestFunctions.class.php, line 416

Class

LdapTestFunctions

Code

public function parseCsv($filepath) {
  $row = 1;
  $table = [];
  if (($handle = fopen($filepath, "r")) !== FALSE) {
    while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
      if (count($data) > 1) {
        $table[] = $data;
      }
    }
    fclose($handle);
  }
  $table_associative = [];
  $headings = array_shift($table);
  foreach ($table as $i => $row) {
    $row_id = $row[0];
    foreach ($row as $j => $item) {
      $table_associative[$row_id][$headings[$j]] = $item;
    }
  }
  return $table_associative;
}