I' have problem csv on upload, First I want to check the duplicate data or column or row before i enter it into the database. I have 2 columns/row, I want to check all the data on the two columns or row before it inserted it into the table.
Note: If duplicates found in all two columns or row it will throw and error or echo the duplicate value, And it will not continue to the insert function.
$stored = [];
$handle2 = fopen($_FILES["charge_file"]["tmp_name"],"r");
while(($data1 = fgetcsv($handle2,1000,",")) !==false){
$charge_emp = trim($data1[0]);
$charge_amount = trim($data1[2]);
// this is the function on checking the duplicates
if (in_array($data1[0], $stored)) { continue;}
$stored[] = $data1[0];
showDups($stored);
// this is my insert function
charges_group_entry($charge_emp,$charge_amount);
}
fclose($handle);
function showDups($array)
{
$array_temp = array();
foreach($array as $val)
{
if (!in_array($val, $array_temp))
{
$array_temp[] = $val;
}
else
{
echo 'duplicate = ' . $val . '<br />';
}
}
}