Skip to content
Advertisement

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

I have two arrays in PHP as follows:

People:

JavaScript

Wanted Criminals:

JavaScript

How do I check if any of the People elements are in the Wanted Criminals array?

In this example, it should return true because 20 is in Wanted Criminals.

Advertisement

Answer

You can use array_intersect().

JavaScript
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement