How can fgetcsv() be used to read a CSV file in PHP and store the data in an array?

To read a CSV file in PHP and store the data in an array, you can use the fgetcsv() function. This function reads a line from an open file and parses it as CSV fields. You can loop through the file line by line, using fgetcsv() to parse each line and store the data in an array.

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

while (($line = fgetcsv($file)) !== false) {
    $data[] = $line;
}

fclose($file);

print_r($data);