title: Export data into CSV file in Symfony
body: <p>I have console app made in Symfony3, where user can import CSV file (which is validate) into database. I need to put records which haven't passed validation into separate file.  </p>
  
  <p>I use LeagueCSV to read CSV file and I try to use it to write unvalidated records but it doesn't work. </p>
  
  <p>This is my code:</p>
  
  <pre><code>$reader = Reader::createFromPath($input-&gt;getArgument('lokalizacja'));
  $reader-&gt;setDelimiter(';');
  $reader-&gt;setHeaderOffset(0);
  
  $results = $reader-&gt;getRecords();
  
  foreach ($results as $row) {
  
    $year = $row['description'];
  
    $isValid = false;
  
    if ($row['qty'] &gt; 0 &amp;&amp; $row['price'] &gt; 0 &amp;&amp; !empty($row['mpn'])) {
  
        $isValid = true;
  
        $rok = filter_var($row['description'], FILTER_SANITIZE_NUMBER_INT);
  
              $product = (new Produkt())
                      -&gt;setMpn($row['mpn'])
                      -&gt;setQty($row['qty'])
                      -&gt;setYear($year)
                      -&gt;setPrice($row['price']);
  
              $this-&gt;em-&gt;persist($product); }
  
    if ($row['qty'] == 0 || $row['price'] == 0 || empty($row['mpn'])) {
  
         $writer = Writer::createFromPath('/path/to/saved/file.csv', 'w+');              
         $writer-&gt;insertOne([$row['mpn'], $row['qty'], $row['price'], 
                        $row['description']]);
  
          continue;
    }                
  }
  
      $this-&gt;em-&gt;flush();
  </code></pre>
  
  <p>All records which passed validation are successfully saved in the database but I have problem with others records. In new CSV file I have only first, one record which haven't passed validation and nothing more. What am I doing wrong? I tried with</p>
  
  <pre><code>$writer-&gt;insertAll($results); //using an array
  </code></pre>
  
  <p>Or with if...else statment but that's nothing.</p>
  
  <p>Also I made ...else statement where unvalidated records are saved in other table in database and its works but I don't know how to immediately convert them into CSV file.</p>