To select the common data from two arrays in PHP, you need to use the array_intersect() function. It compares the value of two given arrays, matches them and returns with the common values. Here’s an example:

$a1=array("a"=>"red","b"=>"green","c"=>"blue","d"=>"yellow");
$a2=array("e"=>"red","f"=>"black","g"=>"purple");
$a3=array("a"=>"red","b"=>"black","h"=>"yellow");

$result=array_intersect($a1,$a2,$a3); print_r($result);

Output:

Array ( [a] => red )

BY Best Interview Question ON 15 Apr 2020