php array_unique 2d ARRAY中的bug

时间:2013-07-06 12:52:38

标签: php regex arrays

我正在使用Array列表,有很多重复

我使用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?

1 个答案:

答案 0 :(得分:1)

默认情况下array_unique compares the items as if they are string,这意味着它实际上将数组转换为字符串(任何转换为​​字符串的数组都是相同的 - 字符串'Array')。所以你必须这样做:

$a = array_unique($a, SORT_REGULAR)