PHP array_intersect + array_flip with array that has values multiple times

前端 未结 2 583
青春惊慌失措
青春惊慌失措 2021-01-14 22:16

I have two arrays:

$arr1 = array(101 => 250, 102 => 250, 103 => 250, 104 => 500, 105 => 500, 106 => 500,);

and

         


        
2条回答
  •  轮回少年
    2021-01-14 22:34

    The following code does the job. I hope it is self-explanatory.

    array_unique(array_intersect_key($arr1, array_flip($arr2)))
    

提交回复
热议问题