PHPize Online / SQLize Online

A A A
Share   Donate   Blog   Popular
Copy Format Clear
Copy
Copy Format Clear
<?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(stream: $handle, length: 0, separator: $this->delimiter)) != false) { yield array_combine($header, $data); } fclose($handle); } private function writeCSV(): void { $fileToWrite = fopen($this->resultingFilePath, 'w'); if ($fileToWrite === false) { throw new ErrorException('Unable to open the file'); } foreach ($this->readCSV() as $value) { if ( $value['Variable_category'] === 'Financial position' && (int)$value['Value'] > 100000 ) { fputcsv($fileToWrite, $value); } } } }
Show:  
Copy