jeudi 28 novembre 2019

Optimize the 'if' statement(PHP)

I want to optimize the 'if' statement when a variable can meet 2 different values, for example:

if($x==5 || $x == 7)
{
//Do something
}

I feel that maybe it is not necessary to have to write the same variable twice, so I wonder if there is a way to optimize that condition. For something similar to this:

if($x== (5 || 7))
{
 //Do something
}

Aucun commentaire:

Enregistrer un commentaire