Array Intersect in the same order PHP

245 Views Asked by At

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.

1

There are 1 best solutions below

0
sajjad rezaei On

You can use array_intersect_assoc as below:

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