title: PHP Array Memory Usage
body: <p>I have a tab-delimited file that I need to be in an array (so I can look for values in it). I had thought that I could iterate through the lines and just push the exploded values into an array, like so:</p>
  
  <pre><code>error_reporting(E_ALL);
  ini_set("memory_limit","20M");
  
  $holder = array();
  $csv = array();
  $lines = file('Path\\To\\File\\2014_04_05_08_48.txt');
  
  for ($a=0; $a&lt;count($lines); $a++) {
      $csv = '';
      $csv = $lines[$a];
      $csv = explode("\t", $csv);
      array_splice($csv, 10);
      array_push($holder, $csv);
  }
  
  print_r($holder);
  </code></pre>
  
  <p>This file is about 11000 lines, 170 fields/line (output of current inventory from a POS system). This file is less than 6MB. I kept getting errors about memory limits being exceeded. Looking here on SO I found that increasing the memory limit was usually a way of covering a memory leak/poor memory usage.</p>
  
  <p>I finally got it to work by setting the memory limit to 20M and stripping each array after the 10th value.</p>
  
  <p>My question is why do I need such a high memory limit to get the file contents into an array? More than 3x the size seems like a lot. Am I doing something wrong?</p>