validating textbox in a for loop
<p>I have a textbox that is in a <code>for</code> loop. I want to validate this textbox if no data is entered then it should display an error message.</p>

<pre><code>  &lt;form method="post" action="test.php"&gt;
     &lt;?php for($i = 0; $i &lt; 2; $i++) { ?&gt;                
        &lt;input type='text' name='txtName[]' required /&gt;                                               
    &lt;?php } ?&gt;  
    &lt;input type="submit" name="btnConfirm" value="Proceed" class="button" /&gt; 
  &lt;/form&gt;


&lt;?php
    $name = $_POST['txtName'];

    if(isset($_POST['btnConfirm'])) {
       if(!empty($name))  { echo "it worked!"; } 
       else { echo "Please enter your name."; }
    }
?&gt;  
</code></pre>

<p>It works when I use this code:  </p>

<pre><code>$name = $_POST['txtName[]'];
</code></pre>

<p>but after I enter data in <code>textbox</code>, it doesn't go to my <code>else</code> statement.</p>
