Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP if in_array for multiple values

I have an array that is generated with anywhere between 3 and 12 values, it generates the array from account information;

$result = $ad->user()->groups($user['username']);

I want to check this array for multiple values (around 4 or 5) and if any of them are in it do what's inside the if, I can do it for one value pretty easily via:

if (in_array("abc",$result)) {  $this->login_session($user); }

Is there a simple way to check this one array for multiple values in it other than consecutive ORs:

    if (in_array("abc",$result) || in_array("123",$result) || in_array("def",$result) || in_array("456",$result) ) {  
    $this->login_session($user); 
    }
like image 461
toups Avatar asked Apr 08 '13 13:04

toups


1 Answers

Try and see if this is helpful:

if(array_intersect($result, array('abc', '123', 'def'))) {
  $this->login_session($user);
}
like image 135
Mircea Soaica Avatar answered Oct 18 '22 08:10

Mircea Soaica