Skip to content

Commit 1f5e100

Browse files
authored
Fix two titles with the same name
1 parent 42047e5 commit 1f5e100

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

parseCSV.php

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22

33
// Created by Yehuda Eisenberg
44

5-
function parseCsv($filename, $header = true){
5+
function parseCsv($filename, $title = true){
66
$dataText = file_get_contents($filename);
77
$dataArr = explode("\n", $dataText);
88

9-
if($header){
9+
if($title){
1010
$names = explode(",", $dataArr[0]);
1111
unset($dataArr[0]);
1212
}
@@ -16,8 +16,16 @@ function parseCsv($filename, $header = true){
1616
$data = explode(",", $data);
1717
$tmp = array();
1818
foreach($data as $i => $dat){
19-
if($header)
20-
$tmp[trim($names[$i])] = trim($dat);
19+
if($title){
20+
if(isset($tmp[trim($names[$i])])){
21+
if(is_string($tmp[trim($names[$i])]))
22+
$tmp[trim($names[$i])] = array($tmp[trim($names[$i])], trim($dat));
23+
else
24+
$tmp[trim($names[$i])][] = trim($dat);
25+
}
26+
else
27+
$tmp[trim($names[$i])] = trim($dat);
28+
}
2129
else
2230
$tmp[$i] = trim($dat);
2331
}

0 commit comments

Comments
 (0)