Unique values in a php array

Discussion in 'PHP' started by Silver89, Feb 18, 2010.

  1. #1
    If I have the following array:

    
    Array (
    [0] => Array ([0] => 2 [1] => 3 [2] => 1 )
    [1] => Array ([0] => 2 [1] => 3 [2] => 3 )
    [2] => Array ([0] => 2 [1] => 3 [2] => 1 )
    [3] => Array ([0] => 2 [1] => 3 [2] => 3 )
    [4] => Array ([0] => 2 [1] => 3 [2] => 1 )
    [5] => Array ([0] => 2 [1] => 3 [2] => 3 )
    [6] => Array ([0] => 2 [1] => 3 [2] => 1 )
    [7] => Array ([0] => 2 [1] => 3 [2] => 3 )
    )
    
    PHP:
    How can I get just the unique values?

    I've tried array_unique but it's multi dimensional so I don't think it's having the required affect.
     
    Silver89, Feb 18, 2010 IP
  2. danx10

    danx10 Peon

    Messages:
    1,179
    Likes Received:
    44
    Best Answers:
    2
    Trophy Points:
    0
    #2
    Ellaborate?

    And can you provide your expected output?
     
    danx10, Feb 18, 2010 IP
  3. Silver89

    Silver89 Notable Member

    Messages:
    2,243
    Likes Received:
    72
    Best Answers:
    0
    Trophy Points:
    205
    #3
    Okay the output I want is the unique values within so:

    
    Array (
    [0] => Array ([0] => 2 [1] => 3 [2] => 1 )
    [1] => Array ([0] => 2 [1] => 3 [2] => 3 )
    )
    
    PHP:
    However with array_unique it's just giving:

    
    Array ( [0] => Array ( [0] => 2 [1] => 3 [2] => 1 ) )
    
    PHP:
     
    Silver89, Feb 18, 2010 IP
  4. joebert

    joebert Well-Known Member

    Messages:
    2,150
    Likes Received:
    88
    Best Answers:
    0
    Trophy Points:
    145
    #4
    serialize each entry, use array_unique on the resulting array, then unserialize each entry.
     
    joebert, Feb 18, 2010 IP
    Silver89 likes this.