What are some best practices for handling CSV files in PHP, especially when it comes to assigning unique numbers to each row?

When handling CSV files in PHP and needing to assign unique numbers to each row, one approach is to use the `fgetcsv()` function to read the file line by line and generate a unique number for each row. This unique number can be based on the row index or any other criteria specific to the data. It's important to ensure that the unique numbers are assigned correctly and consistently to avoid any duplicates.

$csvFile = fopen('data.csv', 'r');

if ($csvFile !== false) {
    $uniqueNumber = 1;

    while (($data = fgetcsv($csvFile)) !== false) {
        // Assign unique number to each row
        $data[] = $uniqueNumber++;

        // Process the data as needed
        print_r($data);
    }

    fclose($csvFile);
} else {
    echo "Error opening CSV file.";
}