Answer the question
In order to leave comments, you need to log in
How to remove row with duplicate value from CSV (PHP)?
There is an array in php array
$list = array (
array('', $_POST['subject'], $_POST['time'], $_POST['text'], $_POST['name_html'],''),
);
$list = array (
array('', $_POST['subject'], $_POST['time'], $_POST['text'], $_POST['name_html'],''),
);
$fp = fopen('db/cards.csv', 'a');
foreach ($list as $fields) {
fputcsv($fp, $fields);
}
fclose($fp);
Answer the question
In order to leave comments, you need to log in
i just want to remove old $_POST['subject'] value from db
<?php
$list = [];
if(($handle = fopen("db/cards.csv", "r")) !== false)
{
while(($data = fgetcsv($handle, 1000, ",")) !== false)
{
$subject = $data[1];
$list[$subject] = $data; //<--- ключевой момент
}
fclose($handle);
}
//теперь в $list только строки с уникальным $subject
print_r($list);
//перезаписываем csv данными из $list
//тут ваш код
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question