Create check multiple values of a variable

Asked

Viewed 266 times

4

I have a set of rules that take 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 goes away with several of these...

I wanted something like:

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

So, if level equals 1 and status equals some word in the list, you enter if.

1 answer

5


You can do this by placing the list of words in an array, and checking whether 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)) {
    // ...
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.