What is the purpose of fgetcsv function in PHP?

The fgetcsv function in PHP is used to read a line from a CSV file and parse it into an array. This function is useful when working with CSV files to easily extract data and manipulate it within a PHP script. By using fgetcsv, you can efficiently read and process CSV files without having to manually parse the data.

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

while (($data = fgetcsv($file)) !== false) {
    // Process the data from the CSV file
    print_r($data);
}

fclose($file);