Purpose:
Array_intersect function takes two or more arrays and returns values that are same with first array.
Code:
1. <?php
2. $names1=array(0=>"Tahreem",1=>"Rizwan",2=>"Anwar");
3. $names2=array(3=>"Tahreem",4=>"Rizwan",5=>"Misbah");
4. print_r(array_intersect($names1,$names2));
5. ?>
Output:
Array ( [0] => Tahreem [1] => Rizwan )
Explanation:
On line 2 and line 3 we have declared two arrays $names1, $names2 and initialize it. On line 4 we have passed both of the arrays to array_intersect function that compares both of the arrays for the same elements it prints the same elements of the array.