Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
CsvMulty.php
Go to the documentation of this file.
1 <?php
12 namespace Magento\Framework\File;
13 
15 {
24  public function getDataPairs($file, $keyIndex = 0, $valueIndex = 1)
25  {
26  $data = [];
27  $csvData = $this->getData($file);
28  $lineNumber = 0;
29  foreach ($csvData as $rowData) {
30  $lineNumber++;
31  if (isset($rowData[$keyIndex])) {
32  if (isset($data[$rowData[$keyIndex]])) {
33  if (isset($data[$rowData[$keyIndex]]['duplicate'])) {
34  $data[$rowData[$keyIndex]]['duplicate']['line'] .= ', ' . $lineNumber;
35  } else {
36  $tmpValue = $data[$rowData[$keyIndex]]['value'];
37  $tmpLine = $data[$rowData[$keyIndex]]['line'];
38  $data[$rowData[$keyIndex]]['duplicate'] = [];
39  $data[$rowData[$keyIndex]]['duplicate']['line'] = $tmpLine . ' ,' . $lineNumber;
40  $data[$rowData[$keyIndex]]['duplicate']['value'] = $tmpValue;
41  }
42  } else {
43  $data[$rowData[$keyIndex]] = [];
44  $data[$rowData[$keyIndex]]['line'] = $lineNumber;
45  $data[$rowData[$keyIndex]]['value'] = isset($rowData[$valueIndex]) ? $rowData[$valueIndex] : null;
46  }
47  }
48  }
49  return $data;
50  }
51 }
getDataPairs($file, $keyIndex=0, $valueIndex=1)
Definition: CsvMulty.php:24