PHP remove array of associative array that have a duplicate values of specific key

前端 未结 3 1093
鱼传尺愫
鱼传尺愫 2021-01-29 13:11

I\'ve a array of associative array

array(xxx) {
 [0]=>
   array(3) {
    [\"group_id\"]=>2
    [\"contact\"]=> \"foo\"
    [\"contact_email\"]=> \"fo         


        
3条回答
  •  佛祖请我去吃肉
    2021-01-29 13:48

    Extract to an array and index by contact_email. Since there cannot be duplicate indexes you'll get the last occurrence:

    $array = array_column($array, null, 'contact_email');
    

    If you want to re-index that back to integers:

    $array = array_values(array_column($array, null, 'contact_email'));
    

提交回复
热议问题