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"]
$arrayUtils->unique(int $sort_flags = SORT_STRING) : ArrayUtils;
$sortFlags
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 numericallySORT_STRING
- compare items as stringsSORT_LOCALE_STRING
- compare items as strings, based on the current locale.
- A filtered array.
$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;
Last modified 2yr ago