array_unique错误地丢弃了值

时间:2013-11-29 22:56:36

标签: php array-unique

我正在尝试使用array_unique来丢弃重复的值。

Array
(
    [0] => Array
        (
            [book_id] => 1203910329
            [author] => Gauci, Joe
            [description] => Paperback. Very Good.
            [isbn] => 9781907374067
            [publisher] =>
            [date] =>
            [currency] => USD
            [price] => 10.97
            [bookseller] => xx
            [bookseller_location] => GBR
            [condition] => 3
            [shipping_ground] => 4.73
            [shipping_expedited] => 6.33
        )

    [1] => Array
        (
            [book_id] => 12312314556
            [author] => Gauci, Joe
            [description] => Paperback. GOOD.
            [isbn] => 9781907374067
            [publisher] =>
            [date] =>
            [currency] => USD
            [price] => 1.84
            [bookseller] => xx
            [bookseller_location] => GBR
            [condition] => 2.5
            [shipping_ground] => 4.73
            [shipping_expedited] => 6.33
        )

    [2] => Array
        (
            [book_id] => 12312314556
            [author] => Gauci, Joe
            [description] => Paperback. GOOD.
            [isbn] => 9781907374067
            [publisher] =>
            [date] =>
            [currency] => USD
            [price] => 1.84
            [bookseller] => xx
            [bookseller_location] => GBR
            [condition] => 2.5
            [shipping_ground] => 4.73
            [shipping_expedited] => 6.33
        )

)

每次使用array_unique($results)时,只返回第一个值

 Array
    (
        [0] => Array
            (
                [book_id] => 1203910329
                [author] => Gauci, Joe
                [description] => Paperback. Very Good.
                [isbn] => 9781907374067
                [publisher] =>
                [date] =>
                [currency] => USD
                [price] => 10.97
                [bookseller] => xx
                [bookseller_location] => GBR
                [condition] => 3
                [shipping_ground] => 4.73
                [shipping_expedited] => 6.33
            )
    )

我要去哪儿array_unique

1 个答案:

答案 0 :(得分:3)

您不能将array_unique与嵌套数组一起使用。使用的比较清楚地记录在案: (string) $elem1 === (string) $elem2