NOVINKA: Najžiadanejšie rekvalifikačné kurzy teraz s 50% zľavou + kurz AI ZADARMO. Nečakaj, táto ponuka dlho nevydrží! Zisti viac:

PHP - array_unique

Trieda

Koreň \ Bez triedy

Metóda - array_unique

(PHP 4 >= 4.0.1, PHP 5, PHP 7)

Removes duplicate elements in an array. In the result array, each value occurs at most once. Keys are not affected. Elements are internally compared as strings using the === operator.

Procedurálne

  • function array_unique (array $array, int $sort_flags = SORT_STRING) : array

Parametre

NázovDátový typPredvolená hodnotaPopis
$arrayarray

The input array.

$sort_flagsint SORT_STRING

An optional parameter. We can use the following flags:

  • SORT_REGULAR - Compares elements without changing the type.
  • SORT_NUMERIC - Compares elements numerically.
  • SORT_STRING - Compares elements as strings.
  • SORT_LOCALE_STRING - Compares elements as strings based on a local setting set by setlocale().

Mávratovej hodnoty

Vracia: array

An array with unique values.

Príklady

<?php
$array = [1, 2, 2, 2, 3, 1, 5, 2, 6, 9, 5];
$unique = array_unique($array);

print_r($unique);

Súvisiace manuály

      Aktivity