title: Why is fgetcsv() function aggregating the consecutive EMPTY fields into ONE field, and putting it into ONE array position?
body: <p>Here is the CSV file:</p>
  
  <p><strong><em>a.csv:</em></strong></p>
  
  <pre><code>"a","b",,"c",,"d","e","f",,"g","h","i","j",,,,,,,,,,,,,,"k",,,,,,,,,,,,,,,"l","m,n","o"
  </code></pre>
  
  <p>Now in this CSV file, <code>,</code> is the delimiting character between fields. So the first field is <code>a</code>, the second field is <code>b</code>, <em>the third field is empty</em>, the fourth field is <code>c</code>, <em>the fifth field is empty again</em>, and so on.</p>
  
  <p>Here is my example code:</p>
  
  <p><strong><em>index.php:</em></strong></p>
  
  <pre><code>$file = fopen("a.csv", "r");
  
  while ( !( ($line = fgetcsv($file, ',', '"')) === false ) ) {
      print_r($line);echo "&lt;br&gt;";
  }
  </code></pre>
  
  <p><strong><em>EXPECTED OUTPUT:</em></strong></p>
  
  <p>I was expecting this code snippet to print something like:</p>
  
  <pre><code>Array ( [0] =&gt; a, [1] =&gt; b [2] =&gt; [3] =&gt; c [4] =&gt; [5] =&gt; d ...so on
  </code></pre>
  
  <p><strong><em>OUTPUT I GOT:</em></strong></p>
  
  <p>Actual output I got:</p>
  
  <pre><code>Array ( [0] =&gt; a, [1] =&gt; b [2] =&gt; ,, [3] =&gt; c [4] =&gt; ,, [5] =&gt; d [6] =&gt; , [7] =&gt; e [8] =&gt; , [9] =&gt; f [10] =&gt; ,, [11] =&gt; g [12] =&gt; , [13] =&gt; h [14] =&gt; , [15] =&gt; i [16] =&gt; , [17] =&gt; j [18] =&gt; ,,,,,,,,,,,,,, [19] =&gt; k [20] =&gt; ,,,,,,,,,,,,,,, [21] =&gt; l [22] =&gt; , [23] =&gt; m,n [24] =&gt; , [25] =&gt; o [26] =&gt; ) 
  </code></pre>
  
  <p><strong><em>QUESTION:</em></strong></p>
  
  <ol>
  <li><p><strong>Firstly, why am I getting those <em>random</em> commas?</strong> I say <em>random</em> because, as you can see, there is a comma after the first element <code>a</code>, then there is no comma after the second element <code>b</code>, and there is no comma after <code>c</code> either (and so on).</p></li>
  <li><p>For the fields which do Not have a value, i.e. which are empty, why is it aggregating several several fields, e.g. <strong>in the field shown at index <code>18</code>, about <code>14</code> EMPTY fields have been aggregated and put into one array position.</strong> Why? The result of this is that this output array was supposed to contain 43 elements, and now it contains 26. </p></li>
  </ol>
  
  <p>How do I fix these problems and get the expected output?</p>
  
  <p><strong><em>Note:</strong> I am able to change the separator and field-enclosure values in the CSV File.</em></p>