Question: I'm doing some validation now in PHP, and I'm running allot of conditional statements, for example:

```

if ($this->email->isValid($email))
return false;
if ($this->username->isValid($username))
return false;

```

ect.. 

Is there a nice way to do this? Or do I just run ten If statements like the ones above?
I can't use `switch` obviously, but I'm looking for that type of solution.. 

P.S... I'm using Zend Framework for validation

Answer: 
Doing something like this is called a Guardian clause. It can be improved so clauses that return the same value should be grouped together.

```
if ($this->email->isValid($email) || $this->username->isValid($username))
{
    return false;
}

```

Or like this, if there are many (btw how I format the if is just so it can read better, any other way should be fine as well)

```
if (
    $this->email->isValid($email) || 
    $this->username->isValid($username) || 
    $this->somethingelse()
   )
{
    return false;
}

```
Maybe something like this:

```
foreach( $form->getElements as $element => $value )
{ 
    if( !$element->isValid( sanitize($value))){
       return false;
    }
}

```

BUT if you are using ZF this is your oneliner answer because you check all the form in one not individual fields:

```
$form = new My_Zend_Form(); // in the controller action that you send the form to

if ( $form->isValid($_POST)) {
    // Success /// do whatever you want with the data
    $data = $form->getValues();
} else {
    //error
}

```