title: PHP if condition to Array to Foreach
body: <p>Example code:
  HTML-</p>
  
  <pre><code>&lt;input type="text" name="title1"/&gt;
  &lt;input type="text" name="title2"/&gt;
  &lt;input type="text" name="title3"/&gt;
  </code></pre>
  
  <p>PHP
  check if above fields has text.</p>
  
  <pre><code>$title1 = null;
  if ($title1)
      $title1= "'1'";
  $title2 = null;
  if ($title2)
      $title1= ",'2'";
  $title3 = null;
  if ($title3)
      $title3= ",'3'";
  </code></pre>
  
  <p>Make Array</p>
  
  <pre><code>$titles = [$title1.$title2.$title3];
  </code></pre>
  
  <p>Foreach</p>
  
  <pre><code>foreach ($titles as $key=&gt;$title) {
      echo '&lt;p&gt;' . $key.$title . '&lt;/p&gt;';
  }
  </code></pre>
  
  <p>It's currently printing only first value when title1 and title2 has text. 
  Can you tell me what is wrong with above codes? Better solution welcome!</p>