douhan0562 2013-11-21 12:51
浏览 56
已采纳

php多维数组:如何删除重复的条目

in fear of duplicating content, i have looked through so many similar SO questions, but i think i need a bit more than code, to tell me how solve my problem- would be lovely with some explaination too.

How do i turn $list:

array(4) {
  [0]=>
  array(2) {
    ["title"]=>
    string(8) "Zambezia"
    ["id"]=>
    int(31)
  }
  [1]=>
  array(2) {
    ["title"]=>
    string(6) "Zarafa"
    ["id"]=>
    int(34)
  }
  [2]=>
  array(2) {
    ["title"]=>
    string(8) "Zambezia"
    ["id"]=>
    int(31)
  }
  [3]=>
  array(2) {
    ["title"]=>
    string(8) "Zambezia"
    ["id"]=>
    int(31)
  }
} 

Into $list:

 array(2) {
      [0]=>
      array(2) {
        ["title"]=>
        string(8) "Zambezia"
        ["id"]=>
        int(31)
      }
      [1]=>
      array(2) {
        ["title"]=>
        string(6) "Zarafa"
        ["id"]=>
        int(34)
      }
    } 

By removing duplicate entries?

  • 写回答

1条回答 默认 最新

  • duanliexi1052 2013-11-21 12:53
    关注

    Use array_unique() with SORT_REGULAR flag.

    $new_array = array_unique($array, SORT_REGULAR);
    

    Output should be:

    Array
    (
        [0] => Array
            (
                [title] => Zambezia
                [id] => 31
            )
    
        [1] => Array
            (
                [title] => Zarafa
                [id] => 34
            )
    
    )
    

    Demo.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 oracle集群安装出bug
  • ¥15 关于#python#的问题:自动化测试
  • ¥15 教务系统账号被盗号如何追溯设备
  • ¥20 delta降尺度方法,未来数据怎么降尺度
  • ¥15 c# 使用NPOI快速将datatable数据导入excel中指定sheet,要求快速高效
  • ¥15 再不同版本的系统上,TCP传输速度不一致
  • ¥15 高德地图点聚合中Marker的位置无法实时更新
  • ¥15 DIFY API Endpoint 问题。
  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿