Question

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?

Was it helpful?

Solution 2

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;
}

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top