Create check multiple values of a variable

5

I have a set of rules that are taking up a lot of space in my code:

if      ($ni == '1' && $status2 == 'Aberto'  ){
$url_edit = "<a href='edit_os.php?id1=$id1'>";

}elseif ($ni == '1' && $status2 == 'Em Andamento'){
$url_edit = "<a href='edit_os.php?id1=$id1'>";

And it goes away with several of these ...

I wanted was something like:

if ($ni == 1 && status2 = LISTA DE PALAVRAS)

So if level is equal to 1 and status is equal to some word in list, enter if .

    
asked by anonymous 15.01.2015 / 00:13

1 answer

6

You can do this by placing the list of words in an array, and verifying that the value of the variable is contained in the list, with in_array :

$statusPermitidos = array('Aberto', 'Em Andamento');
if ($ni == '1' && in_array($status2, $statusPermitidos)) {
    // ...
}
    
15.01.2015 / 00:21