0
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?

2 Answers 2

3

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.

Sign up to request clarification or add additional context in comments.

5 Comments

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

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.