0

我正在处理有很多重复的数组列表

我使用 array_unique

foreach ($aData as $test) {
   preg_match( "~http://www.site.com/.*?/~", $test,$match) ;
      $a[] = $match;

}

输出

Array ( 

    [0] => Array ( [0] => */liars-all-2013-hdrip-xvid-s4a/ ) 
    [1] => Array ( [0] => */liars-all-2013-hdrip-xvid-s4a/ ) 
    [2] => Array ( ) 
    [3] => Array ( [0] => */liars-all-2013-hdrip-xvid-s4a/ ) 
    [4] => Array ( [0] => */mt-zion-2013-dvdrip-xvid-fihvid/ ) 
    [5] => Array ( [0] => */mt-zion-2013-dvdrip-xvid-fihvid/ ) 
    [6] => Array ( [0] => */mt-zion-2013-dvdrip-xvid-fihvid/ ) 
    [7] => Array ( [0] => */the-ghastly-love-of-johnny-x-2012-webrip-xvid-fan0n/ ) 
    [8] => Array ( [0] => */the-ghastly-love-of-johnny-x-2012-webrip-xvid-fan0n/ ) 
    [9] => Array ( [0] => */the-ghastly-love-of-johnny-x-2012-webrip-xvid-fan0n/ ) 
    [10] => Array ( [0] => */kung-fu-panda-good-croc-bad-croc-2013-dvdrip-x264-ac3-deep1007/ ) 
    [11] => Array ( [0] => */kung-fu-panda-good-croc-bad-croc-2013-dvdrip-x264-ac3-deep1007/ ) 
    [12] => Array ( [0] => */kung-fu-panda-good-croc-bad-croc-2013-dvdrip-x264-ac3-deep1007/ ) 
    [13] => Array ( [0] => */a-viking-saga-the-darkest-day-2013-1080p-bluray-x264-ulshd/ ) 
    [14] => Array ( [0] => */a-viking-saga-the-darkest-day-2013-1080p-bluray-x264-ulshd/ ) 
    [15] => Array ( [0] => */a-viking-saga-the-darkest-day-2013-1080p-bluray-x264-ulshd/ ) 
    [16] => Array ( [0] => */dead-man-down-2013-extras-720p-bluray-x264-phd/ ) 
    [17] => Array ( [0] => */dead-man-down-2013-extras-720p-bluray-x264-phd/ ) 
    [18] => Array ( [0] => */dead-man-down-2013-extras-720p-bluray-x264-phd/ ) 
    [19] => Array ( [0] => */spider-baby-1968-720p-bluray-x264-geckos/ ) 
    [20] => Array ( [0] => */spider-baby-1968-720p-bluray-x264-geckos/ ) 
    [21] => Array ( [0] => */spider-baby-1968-720p-bluray-x264-geckos/ ) 
    [22] => Array ( [0] => */drift-2013-bluray-720p-750mb-direct-download/ ) 
    [23] => Array ( [0] => */drift-2013-bluray-720p-750mb-direct-download/ ) 
    [24] => Array ( [0] => */drift-2013-bluray-720p-750mb-direct-download/) 
    [25] => Array ( [0] => */beautiful-creatures-2013-720p/ ) 
    [26] => Array ( [0] => */beautiful-creatures-2013-720p/ ) 
    [27] => Array ( [0] => */beautiful-creatures-2013-720p/ ) 
    [28] => Array ( [0] => */death-race-3-inferno-2012-bluray-720p-direct-download/ ) 
    [29] => Array ( [0] => */death-race-3-inferno-2012-bluray-720p-direct-download/ ) 
    [30] => Array ( [0] => */death-race-3-inferno-2012-bluray-720p-direct-download/ ) 
)

看起来 array_unique 无法深入到数组中:[]**[x]** 所以我在 array_unique 之后得到的唯一东西是我的第一个 [0][string] 我试图只使用 $match 但它只显示最后一个无用的字符串

那么我该如何解决这个BUG呢?

4

1 回答 1

1

默认情况下array_unique ,将项目作为字符串进行比较,这意味着它实际上将数组转换为字符串(并且任何转换为​​字符串的数组都是相同的 - 字符串 'Array')。所以你必须这样做:

$a = array_unique($a, SORT_REGULAR)

于 2013-07-06T16:04:26.180 回答