src/Collection/ArrayCollection.php
public function unique(?callable $callback = null): ArrayCollection
    {
        if ($callback === null) {
            return new static(array_unique($this->items, SORT_REGULAR));
        }
        $set = [];

        return $this->filter(function ($value, $key) use ($callback, &$set) {
            $hash = $callback($value, $key);
            if (isset($set[$hash])) {
                return false;
            }
            $set[$hash] = true;

            return true;
        });
    }
public function unique(?callable $callback = null): ArrayCollection
    {
        if ($callback === null) {
            return new static(array_unique($this->items, SORT_REGULAR));
        }
        $set = [];

        return $this->filter(function ($value, $key) use ($callback, &$set) {
            $hash = $callback($value, $key);
            if (isset($set[$hash])) {
                return false;
            }
            $set[$hash] = true;

            return true;
        });
    }
public function unique ( ? callable $ callback = null ) : ArrayCollection { if ( $ callback === null ) { return new static ( array_unique ( $ this -> items , SORT_REGULAR ) ) ; } $ set = [ ] ; return $ this -> filter ( function ( $ value , $ key ) use ( $ callback , & $ set ) { $ hash = $ callback ( $ value , $ key ) ; if ( isset ( $ set [ $ hash ] ) ) { return false ; } $ set [ $ hash ] = true ; return true ; } ) ; }
Creates a collection with unique items

Optional callback should return a string value for equality comparison.

Callback signature:

<code>
function ($value, $key): string {}
</code>

@param callable|null $callback The callback function

@return ArrayCollection
Creates a collection with unique items