check multiple values exists php array

后端 未结 2 2091
清酒与你
清酒与你 2020-12-05 19:22

I have an array in PHP

$permission = array( \"admin\", \"moderator\", \"guest\"  );

and i have another array

$userRoles = a         


        
相关标签:
2条回答
  • 2020-12-05 19:38

    Use array_intersect

    array_intersect — Computes the intersection of arrays

    array array_intersect ( array $array1 , array $array2 [, array $ ... ] )

    array_intersect() returns an array containing all the values of array1 that are present in all the arguments. Note that keys are preserved.

    Read

    0 讨论(0)
  • 2020-12-05 20:01

    Use array_intersect

    count(array_intersect($permission, $userRoles));
    
    0 讨论(0)
提交回复
热议问题