title: Parsing two files, and comparing strings
body: <p>So I have two files, formatted like this:</p>
  
  <p>First file</p>
  
  <pre><code>adam 20 male
  ben 21 male
  </code></pre>
  
  <p>Second file</p>
  
  <pre><code>adam blonde
  adam white
  ben  blonde
  </code></pre>
  
  <p>What I would like to do, is use the instance of adam in the first file, and search for it in the second file and print out the attributes.</p>
  
  <p>Data is seperated by tab "\t", so this is what I have so far.</p>
  
  <pre><code>$firstFile = fopen("file1", "rb"); //opens first file
  $i=0;
  $k=0;
  while (!feof($firstFile) ) { //feof = while not end of file
  
  $firstFileRow = fgets($firstFile);  //fgets gets line
  $parts = explode("\t", $firstFileRow); //splits line into 3 strings using tab delimiter
  
  $secondFile= fopen("file2", "rb");                          
          $countRow = count($secondFile);                 //count rows in second file     
          while ($i&lt;= $countRow){     //while the file still has rows to search                       
              $row = fgets($firstFile);   //gets whole row                                
              $parts2 = explode("\t", $row);              
              if ($parts[0] ==$parts2[0]){                    
              print $parts[0]. " has " . $parts2[1]. "&lt;br&gt;" ; //prints out the 3 parts
              $i++;
              }
          }
  
  
  }
  </code></pre>
  
  <p>I cant figure out how to loop through the second file, get each row, and compare to the first file.</p>