views:

41

answers:

2
print_r($tokens);
$tokens = array_unique($tokens);
print_r($tokens);

Gives the following output:

Array
(
    [0] => Array
        (
            [Class_ID] => 32709
        )

    [1] => Array
        (
            [Class_ID] => 34682
        )

    [2] => Array
        (
            [Class_ID] => 34818
        )

)
Array
(
    [0] => Array
        (
            [Class_ID] => 32709
        )

)

I don't want it to be changing anything with that array_unique, since the Class_ID values are different.. whats up?

+3  A: 

From documentation:

Note: Two elements are considered equal if and only if (string) $elem1 === (string) $elem2. In words: when the string representation is the same. The first element will be used.

All your elements toString are Array.

Chacha102
Ah, didn't know that. I solved it by specifying SORT_NUMERIC on the sort_flag param.
babonk
That's correct, you will need to iterate through them with `in_array()` to see if you have duplicates.
alex
@alex, see above i was able to get it with that parameter
babonk
@babonk: that just because you're lucky this time. Let try with array that has some item equa/same as some others.
Bang Dao
anyone know how i could do this, then?
babonk
A: 

Found a function from php.net that does array_unique on multi-dimensional arrays:

function super_unique($array) //array unique for multi 
{
  $result = array_map("unserialize", array_unique(array_map("serialize", $array)));

  foreach ($result as $key => $value)
  {
    if ( is_array($value) )
    {
      $result[$key] = super_unique($value);
    }
  }

  return $result;
}
babonk