-
Notifications
You must be signed in to change notification settings - Fork 0
/
csvfile.php
57 lines (46 loc) · 1.21 KB
/
csvfile.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<?php
//The code read multiple data and compare both data and also save it as new csv file
$handle = fopen("others.csv", "r");
// Now check file 2 for matches
$handle = fopen("new.csv", "r");
// Grab the header row from the file first
$header = fgetcsv($handle, 1000);
echo "<pre>Header data\n";
print_r($header);
header("content-type: text/plain");
$array = [];
$i = 0;
$csv1 = "new.csv";
$csv2 = "others.csv";
// Load file 1 into an array
// Skip row 1
if (($handle = fopen($csv1, "r")) !== FALSE){
while (($data = fgetcsv($handle)) !== FALSE){
if($i == 0){$i++; continue;}
$array[] = $data;
$i++;
}
fclose($handle);
}
$i = 0;
// Load file 2 into the array if the values don't exist
// Skip row 1
if (($handle = fopen($csv2, "r")) !== FALSE){
while (($data = fgetcsv($handle)) !== FALSE){
if($i == 0){$i++; continue;}
$inarray = false;
foreach($array as $itm){
if(in_array($data[1], $itm)){
$inarray = true;
break;
}
}
if(!$inarray){
$array[] = $data;
}
$i++;
}
fclose($handle);
}
print_r($array);
?>