title: PHP read a large file line by line code modifies to read selected lines
body: <p>I have large text file that contain 800 K lines size 60 MB.I tried this code </p>
  
  <pre><code>$fileData = function() {
      $file = fopen('800K.txt','r');
      if (!$file)
          die('file does not exist or cannot be opened');
      while (($line = fgets($file)) !== false) {
          yield $line;
      }
      fclose($file);
  };
  
  foreach ($fileData() as $line) {
     echo $line.'&lt;br&gt;';
  }
  </code></pre>
  
  <p>It really works : ).but con is it reads all line 800 K lines :( ....... it is possible convert into for loop , so it will be easy to selected line like </p>
  
  <pre><code>for ($i=1; $i&lt;=10000; $i++){ 
  $line=trim($lines[$i]); 
  }
  
  
  
  ANSWER :
  $i=0;  //// start number
  foreach ($fileData() as $line) {
     if($i==100) break;  ///// end number
     echo $line.'&lt;br&gt;';
     $i++; 
  }
  </code></pre>