arrayutils
  • Home
  • 📖How to use?
    • âš¡Installation
  • 📖Methods
    • âš¡Static method
      • static from()
      • static of()
      • static mapToArray()
    • âš¡Generic method
      • join()
      • every()
      • some()
      • reduce()
        • reduceRight()
      • sum()
      • pop()
      • shift()
      • includes()
      • keyExists()
      • indexOf()
      • find()
        • findIndex()
      • first()
        • keyFirst()
      • last()
        • keyLast()
      • random()
        • keyRandom()
      • splice()
    • âš¡Chain method
      • chunk()
      • column()
      • combine()
      • concat()
        • concatSoft()
      • countValues()
      • diff()
        • diffAssoc()
        • diffKey()
      • fill()
        • fillKeys()
      • filter()
      • flat()
        • flatMap()
      • flip()
      • forEach()
      • intersect()
        • intersectAssoc()
        • intersectKey()
      • keys()
      • map()
        • mapAssoc()
        • mapKey()
      • pad()
      • push()
      • replace()
      • reverse()
      • slice()
      • sort()
        • sortKey()
      • unique()
      • unshift()
      • values()
  • 📖Suffixes
    • âš¡Suffix - From
    • âš¡Suffix - As
  • links
    • 📌Github repo
    • 📌Packagist project
    • 📌Poggit project
Powered by GitBook
On this page
  • Syntax
  • Parameter
  • Return value
  • Prefixing
  • References
  1. 📖Methods
  2. ⚡Chain method

unique()

The unique() method removes duplicate values

PrevioussortKey()Nextunshift()

Last updated 4 years ago

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

  • $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 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

PHP: array_chunk - Manual
Logo