PHP verify if every $array[$key] is not empty
<p>So, i have this code that seems to be doing the mechanical work correctly, avoiding to write on tables if one or more fields from a form are left empty, but the echos and messages aren't working as they supposed to:</p>

<p>SOLUTION TO THE PROBLEM:
I don't believe this will be useful to anyone, but just for the record, the solution is simple:</p>

<pre><code>$campos = array('nome','morada','email','telemovel','codigopostal','vat');
foreach ($campos as $key =&gt; $campo) {
    $campos[$key] = $_GET[$campo];
    if(!isset($_GET[$campo])|| empty($_GET[$campo])){
                header("Location: ../index.php?erro=".$campo);
                $verifica=FALSE;
                die();
            }else{
                $verifica=TRUE;
            }
}
</code></pre>

<p>This will give me some problems, not what i really wanted but solves the logical problems i was having. Thanks to you all guys.</p>

<pre><code>$campos = array('nome','morada','email','telemovel','codigopostal','vat');
foreach ($campos as $key =&gt; $campo) {
    $campos[$key] = ($_GET[$campo]);
    while(list($key, $campo)= each($campos))
            if(!isset($_GET[$campo])|| $_GET[$campo]==""){
                echo("não preencheu um dos campos");
                $verifica = FALSE;
                die();
            }else{
        echo $_GET[$campo]." \r\n";}
        $verifica = TRUE;
}

if($verifica==TRUE){
some irrelevant code.
}
</code></pre>

<p>As i said, the code itself is working flawlessly, BUT if i only left 2 empty fields on the form, the echo $_GET[$campo] will be working even though the variable $verifica will be set as FALSE</p>

<p>AN HINT:</p>

<p>One of the fields is making the code to fail, is the second one, so, if i do this:</p>

<pre><code>../phcexport.php?nome=myname&amp;morada=&amp;codigopostal=postcode&amp;email=@.com&amp;vat=12312­3&amp;telemovel=00800
</code></pre>

<p>And ignore the second value from the array, the code will work like a charm, i can try as many combinations as i can as long as i left the second field empty, it will work properly, giving me the error "some field is empty", in this case i know it is, the "morada" is empty, and if i fill it in the code says "its ok, all filled in" BUT the "morada" should be the last to be filled so the code works. Funny... (I'm sorry about all the text to describe the problem, i'm Portuguese)</p>

<p>EDIT2: For the rest of the code i need to use $campos[$key], so attribute a key to the arrays is essencial.</p>
