Hi! Could we please enable some services and cookies to improve your experience and our website?
Online Sandbox for SQL and PHP: Write, Run, Test, and Share SQL Queries and PHP Code
<?php
private function readCSV(): Generator
{
$handle = fopen($this->filePath, "r");
if ($handle === false) {
throw new ErrorException('Unable to open the file.');
}
$header = fgetcsv($handle, 0, $this->delimiter);
while (($data = fgetcsv($handle, 0, $this->delimiter)) != false) {
yield array_combine($header, $data);
}
fclose($handle);
}