'Array Intersect in the same order PHP

I have 2 arrays:

$array1 = array("1","2","3","4","5");
$array2 = array("7","2","3","1","5");

What I want to do is match the values in $array1 and $array2 strictly in order.

The desired output should be 2, 3 and 5 since 1 is not in the same order. I've tried array_intersect but it only matches array values and not taking account their order.

Thanks in advance.



Solution 1:[1]

You can use array_intersect_assoc as below:

$result = array_intersect_assoc($array1 , $array2 );

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 sajjad rezaei