-3

I have two arrays that list people, and I'm trying to figure out which people are in both arrays.

$employees = Array("bob", "john", "jerry", "mike");
$homies = Array("bob", "john", "arnold");

I basically need to know which dudes are both employees and homies (in this case, bob and john) so that I have a new array:

$employees_and_homies = Array("bob", "john");

I looked at like a dozen other questions on here, but I'm lost and nothings working for this particular case.

user2250471
  • 1,002
  • 3
  • 10
  • 23

2 Answers2

3

array_intersect():

$employees_and_homies = array_intersect($employees, $homies);
AbraCadaver
  • 78,200
  • 7
  • 66
  • 87
1
print_r(array_intersect ($employees, $homies));

@Ref : http://in1.php.net/array_intersect

Pankaj Garg
  • 1,272
  • 15
  • 21