Better way of handling isset/!empty? $controller = new UserController();

if (isset($_POST['submitform']))
{   
    $validated = false;

    $inputs = array (
        'username', 'email', 'password',
        'repassword', 'password_f', 'repassword_f',
        'display'
    );

    $i = 0;

    foreach ($inputs as $key)
    {
        if (isset($_POST[$key]) &amp;&amp; !empty($_POST[$key]))
        {
            $i++;
            if ((int)$i == count($inputs))
            {
                $validated = true;
                break;
            }
            else
            {
                $controller-&gt;error = "";
                break;
            }
        }
    }

    if ($validated)
    {
        echo 2;
    }
}


So let's overview the code.

First we are checking if the form was submitted.

Then we are creating a new boolean $validated and setting it false by default.

Then we created our array with the POST names.

Now the checking part, setting variable int i to 0 by default.
Now we are looping through the array elements.

Checking if the current index was set or not empty, if yes, add +1 to int $i.

Once int $i hits the number of counted elements of our array, set $validated to true, and break out of the array, else parse error and break out.

Then we are checking, if bool $validated is true, then echo 2.

Is it a good way of doing this? Is there any cleaner/better way?
I'd do this instead:

function validateForm() {
    if (!isset($_POST['submitform']))
        return false; // Maybe $controller-&gt;error = "Something"; as well?
    $inputs = array (
        'username', 'email', 'password',
        'repassword', 'password_f', 'repassword_f',
        'display'
    );
    foreach ($inputs as $key)
        if (empty($_POST[$key]))
        {
            global $controller;
            $controller-&gt;error = "";
            return false;
        }
    return true;
}
...
if (valudateForm()) {
    echo 2;
} else {
    // Form data not ok
}


Seems cleaner, no flags, no counting array elements, validation has its own function,...