1

I have this array (decoded from JSON, output with print_r):

stdClass Object
(
    [data] => Array
        (
            [0] => stdClass Object
                (
                    [item] => te
                    [date] => 13.10
                )
            [1] => stdClass Object
                (
                    [item] => te
                    [date] => 13.10
                )
            [2] => stdClass Object
                (
                    [item] => tr
                    [date] => 13.10
                )
        )
)

But now I have to remove all the duplicates. If I try $result = array_unique($array, SORT_REGULAR); $result is null.

Can someone spot my mistake?

Francis
  • 343
  • 2
  • 5
  • 16

1 Answers1

3

This is a stdClass object, not an array. When you decode by using the function json_decode, you need to pass the parameter "true" to have an array:

$array = json_decode($json, true);

Edit: As people noticed in the comments, the actual array exists in $array['data'], so the array_unique must be applied on $array['data'] instead of $array.

SamHecquet
  • 1,818
  • 4
  • 19
  • 26