title: PHP: Explode a file and only output parts that has a value
body: <p>Php noob.</p>
  
  <p>I have this text file (names.txt) with comma separated names and codes. Looks similar to this:</p>
  
  <pre><code>John doe, 123456, 876543
  Mary Ann, 456878
  Ben Anderson, 987554, 097532, 873445
  </code></pre>
  
  <p>As you can see each name can have a different amount of codes ranging from one up to 10.
  What I want to do is to output this information as a table</p>
  
  <p>I tried this:</p>
  
  <pre><code>&lt;table&gt;
  &lt;?php
  $file_handle = fopen("names.txt", "rb");
  
  while (!feof($file_handle) ) {
  
  $line_of_text = fgets($file_handle);
  $parts = explode(',', $line_of_text);
  
  echo "&lt;tr&gt;";
  echo "&lt;td&gt;&lt;strong&gt;" . $parts[0] ."&lt;/strong&gt;&lt;/td&gt;";
  echo "&lt;td&gt;" . $parts[1] . "&lt;/td&gt;";
  echo "&lt;td&gt;" . $parts[2] . "&lt;/td&gt;";
  echo "&lt;td&gt;" . $parts[3] . "&lt;/td&gt;";
  echo "&lt;td&gt;" . $parts[4] . "&lt;/td&gt;";
  echo "&lt;td&gt;" . $parts[5] . "&lt;/td&gt;";
  echo "&lt;td&gt;" . $parts[6] . "&lt;/td&gt;";
  echo "&lt;td&gt;" . $parts[7] . "&lt;/td&gt;";
  echo "&lt;td&gt;" . $parts[8] . "&lt;/td&gt;";
  echo "&lt;td&gt;" . $parts[9] . "&lt;/td&gt;";
  echo "&lt;td&gt;" . $parts[10] . "&lt;/td&gt;";
  echo "&lt;/tr&gt;";
  }
  
  fclose($file_handle);
  
  ?&gt;
  &lt;/table&gt;
  </code></pre>
  
  <p>This does not work because sometimes $parts[] will be empty and there is nothing to output and I get an error. Undefined offset.
  How would I go about doing this and only "echo" the $parts[] when it has a value?</p>