删除php中两个数组中找不到的元素

Say you have the following two array:

     array1 = dogs, cat, rat, pig
     array2 = dogs, cat, pig

I want to compare these two arrays and remove elements that are not found in these two arrays to create a new array.

So the above two arrays would become:

tags = dogs, cat, pig 

Is there a function in php for this?

Try array_intersect (click to see documentation).

BTW: This was the first search result for PHP array intersect...

You can use array_intersect

$array1 = array("a" => "green", "red", "blue");
$array2 = array("b" => "green", "yellow", "red");
$result = array_intersect($array1, $array2);
print_r($result);

The $result would be:

Array
(
    [a] => green
    [0] => red
)