empty space validation in PHP with a for loop
<p>as you can see, I have a simple registration form, and a PHP script just to validate some fields. The idea here is, that if you have 20+ fields, and you required at-least the user to fill .. <strong>username, lastname and age</strong>, then you would store it in an array like I have done below. </p>

<p><code>$needed = array("username", "lastname", "age");</code> So, as you can see in the code, I do a <code>for</code> loop to check if one of them is filled, 
now the code works for the most part. for ex: if you don't fill the three fields it will say </p>

<blockquote>
  <p>You must fill username to continue</p>
  
  <p>You must fill lastname to continue</p>
  
  <p>You must fill age to continue</p>
</blockquote>

<p>But, if You fill on field and left the other two, or fill two and then leave one, it will just echo <code>'&lt;p&gt;Required fileds are filled&lt;/p&gt;';</code> </p>

<p>So, the problem here is that, all fields should be filled before the script can go to saying <code>echo '&lt;p&gt;Required fileds are filled&lt;/p&gt;';</code></p>

<pre><code>&lt;pre&gt;
&lt;form action='' method='POST'&gt;
    &lt;input type='text' name='username' /&gt;
    &lt;input type='text' name='lastname' /&gt;
    &lt;input type='text' name='age' /&gt;
    &lt;input type='text' name='gender' /&gt;
    &lt;input type='text' name='country' /&gt;
    &lt;input type='submit' name='reqirester' /&gt;
&lt;/form&gt;


&lt;?php 

    $needed = array("username", "lastname", "age");

  if($_POST):
    $check = NULL;
for($i=0; $i &lt; count($needed); $i++){

        if($_POST[$needed[$i]] == ''){
          echo '&lt;p&gt;You must fill '.$needed[$i].' to continue&lt;p/&gt;';
        break;  

        }else {
            echo '&lt;p&gt;Required fileds are filled&lt;/p&gt;';
        }
    }
 endif;
</code></pre>
