unique()

The unique() method removes duplicate values

Example.php
<?php
use kim\present\utils\arrays\ArrayUtils;

$arrayUtils = ArrayUtils::from(["a", "a", "a", "b", "c", "c", "d"]);

$arrayUtils->unique();
// expected output: ["a", "b", "c", "d"]

Syntax

$arrayUtils->unique(int $sort_flags = SORT_STRING) : ArrayUtils;

Parameter

  • Used to modify the sorting behavior using these values:

    Sorting type flags:

    • SORT_REGULAR - compare items normally (don't change types)

    • SORT_NUMERIC - compare items numerically

    • SORT_STRING - compare items as strings

    • SORT_LOCALE_STRING - compare items as strings, based on the current locale.

Return value

  • A filtered array.

Prefixing

$arrayUtils->uniqueAs(int $sort_flags = SORT_STRING) : array;
ArrayUtils::uniqueFrom(iterable $from, int $sort_flags = SORT_STRING) : ArrayUtils;
ArrayUtils::uniqueFromAs(iterable $from, int $sort_flags = SORT_STRING) : array;

References

Last updated