simplify a great IF!

Asked

Viewed 38 times

-1

I have the following condition to test:

if (isset($_GET["cadastrarMembro"]) && (
                   $_SESSION["acesso"]["idAcesso"] == 3 
                   $_SESSION["acesso"]["idAcesso"] == 5 
                   $_SESSION["acesso"]["idAcesso"] == 6 
                   $_SESSION["acesso"]["idAcesso"] == 10 
                                         ) {

//FAZ ALGO AQUI
}

I’d like to simplify with something like this:

if (isset($_GET["cadastrarMembro"]) && $_SESSION["acesso"]["idAcesso"] IN (3, 5, 6 , 10)) {
//FAZ ALGO AQUI
}

How to do this?

1 answer

5


if (isset($_GET["cadastrarMembro"]) && in_array($_SESSION["acesso"]["idAcesso"], [3, 5, 6, 10])) {
//FAZ ALGO AQUI
}
  • Fit to get here this way if (isset($_GET["register"Member"]) && in_array($_SESSION["access"]["idAccess"], array(3, 5, 6 , 9, 10))) {} but yours got better

Browser other questions tagged

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