Checking to see if one array's elements are in another array in PHP

前端 未结 7 1879
闹比i
闹比i 2020-11-27 13:26

I have two arrays in PHP as follows:

People:

Array
(
    [0] => 3
    [1] => 20
)

Wanted Criminals:

7条回答
  •  感动是毒
    2020-11-27 13:53

    if 'empty' is not the best choice, what about this:

    if (array_intersect($people, $criminals)) {...} //when found
    

    or

    if (!array_intersect($people, $criminals)) {...} //when not found
    

提交回复
热议问题