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?

图片转代码服务由CSDN问答提供 功能建议

由于害怕复制内容,我查看了很多类似的SO问题,但我想我还需要更多 比起代码,告诉我如何解决我的问题 - 通过一些解释也会很可爱。

如何转换$ 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“\  n [“id”] => 
 int(31)
} 
} 
   
 
 

进入$ list:

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

删除重复的条目 ?

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

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.

    点赞 评论

相关推荐 更多相似问题