I would like to ask for help with this task: I have large CSV: 680 columns x 1300 rows and I need to parse it by columns (I need to have array of arrays of column values).
I use this code for this:
$input = "data/input.csv";
if (($handle = fopen($input, "r")) !== false) {
$filesize = filesize($input);
while (($data = fgetcsv($handle, $filesize, "$")) !== false) {
for ($i = 0; $i < count($data); $i++) {
$this->columns[$i][] = $data[$i];
}
}
fclose($handle);
Problem is, that I get this error
Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 16384 bytes) in /www/classes/Analyser.php on line 72
line 72 is $this->columns[$i][] = $data[$i];
My hosting does not allow me to increase the memory limit. Is there a way to write the code efficiently, so there is no need for so much memory, or is it just problem of such large CSV?
Thanks everyone.