How can the issue of memory exhaustion be addressed when reading CSV files with fgetcsv in PHP?

Memory exhaustion when reading CSV files with fgetcsv in PHP can be addressed by processing the file line by line instead of loading the entire file into memory at once. This can be achieved by using a loop to read each line of the CSV file individually and process it accordingly. By doing so, only one line of the file is loaded into memory at a time, reducing the risk of memory exhaustion.

$filename = 'example.csv';
if (($handle = fopen($filename, 'r')) !== FALSE) {
    while (($data = fgetcsv($handle)) !== FALSE) {
        // Process each line of the CSV file here
    }
    fclose($handle);
}