Created
          January 27, 2021 11:22 
        
      - 
      
- 
        Save Padilo300/dfb7d7c9decdda4b8e837b9012a4791e to your computer and use it in GitHub Desktop. 
    csv generator
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | class CsvReader{ | |
| protected $file; | |
| public function __construct($filePath) { | |
| $this->file = fopen($filePath, 'r'); | |
| } | |
| public function rows() | |
| { | |
| while (!feof($this->file)) { | |
| $row = fgetcsv($this->file, 4096); | |
| yield $row; | |
| } | |
| return; | |
| } | |
| } | |
| $csv = new CsvReader("file.csv"); | |
| foreach ($csv->rows() as $row) { | |
| // do | |
| } | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment