How can PHP be used to retrieve specific entries from a CSV file based on a unique ID?
To retrieve specific entries from a CSV file based on a unique ID in PHP, you can read the CSV file line by line, extract the unique ID from each line, and compare it to the desired ID. When a match is found, you can store the corresponding entry or perform any desired action.
$csvFile = 'data.csv';
$uniqueID = '123';
if (($handle = fopen($csvFile, 'r')) !== false) {
while (($data = fgetcsv($handle, 1000, ',')) !== false) {
if ($data[0] == $uniqueID) {
// Found entry based on unique ID
$specificEntry = $data;
break;
}
}
fclose($handle);
}
// Use $specificEntry as needed