title: Split a Comma Separated Value of a Field
body: <p>I am trying to import a CSV for a shop, with a subset of data from an existing CSV file. I need to split one item from a column (column 3, <code>category_id</code>) that contains multiple comma-separated values, then combine it with one other column (<code>Product_id</code>) to produce multiple rows in the import CSV.  See the following examples.</p>
  
  <p><strong>Original CSV</strong></p>
  
  <pre><code>Product_id;article_id;category_id;
  "1";"0001";"2,4,6"
  </code></pre>
  
  <p>Need it into a <strong>new CSV file</strong></p>
  
  <pre><code>Product_id;category_id    
  "1";"2"    
  "1","4"    
  "1","6"
  </code></pre>
  
  <p>I tried just the <code>fegetcsv</code> function to read in the CSV and to printout the whole into an array but I have no idea what to do next.</p>
  
  <pre><code>&lt;?php
  $handle = fopen ("articles.csv","r");
  while ( ($data = fgetcsv ($handle, 1000, ";")) !== FALSE ) {
  $column3[] = $data[3];
  }
  fclose ($handle);
  //edit:
  print_r($column3);
  ?&gt; 
  </code></pre>
  
  <p>I get:</p>
  
  <pre><code>Array ([0] =&gt; category_id [1] =&gt; 1 [2] =&gt; 0001 [3] =&gt; 2,4,6
  </code></pre>