1.

How to get common values from two array in php?

Answer»

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 )



Discussion

No Comment Found