1

there is better way to do this? A more efficient or elegant in PHP? Like an SQL IN ?

This is the code

if ($rol == 1 || $rol == 2 || $rol == 3 || $rol == 5 || $rol == 6 || $rol == 8 ) { 
Rizier123
  • 58,877
  • 16
  • 101
  • 156
  • 7
    *Like an SQL **IN** ??* You are very close. Google: `PHP in_array` <- Here you go – Rizier123 Aug 06 '15 at 19:34
  • You could use a bit mask. It makes sense for some status/role type properties. More [here](http://stackoverflow.com/questions/11880360/how-to-implement-a-bitmask-in-php). – ficuscr Aug 06 '15 at 19:42

1 Answers1

4

Put your numbers in array then use in_array PHP function:

$array = array(1,2,3,4,5,6,8);
if(in_array($rol, $array, true))
{
//Yaay we got a hit ! 
}
Wahib Mkadmi
  • 627
  • 2
  • 9
  • 26