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

前端 未结 7 1877
闹比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:37

    That code is invalid as you can only pass variables into language constructs. empty() is a language construct.

    You have to do this in two lines:

    $result = array_intersect($people, $criminals);
    $result = !empty($result);
    

提交回复
热议问题