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 - sort

Trieda

Koreň \ Bez triedy

Metóda - sort

(PHP 4, PHP 5, PHP 7)

Sorts values in an array from the lowest to the highest.

The function re-indexes the array. More precisely, it removes the keys and creates new ones.

Internally, the sort is implemented by the "Quick sort algorithm":https://www.ict.social/…ting-numbers.

Procedurálne

  • function sort (array &$array, int $sort_flags = SORT_REGULAR) : bool

Parametre

NázovDátový typPredvolená hodnotaPopis
&$arrayarray

The input array.

$sort_flagsint SORT_REGULAR

The optional parameter. We can use the following flags:

  • SORT_REGULAR - Compares elements without changing the type.
  • SORT_NUMERIC - Compares elements as numbers.
  • SORT_STRING - Compares elements as strings.
  • SORT_LOCALE_STRING - Compares elements as strings based on a local setting set by setlocale().
  • SORT_NATURAL - Compares elements as strings using "natural ordering". For example "10.txt will be after 2.txt".
  • SORT_FLAG_CASE - Compares strings case-insensitively. It can be combined (using |) with SORT_STRING and SORT_NATURAL.

Mávratovej hodnoty

Vracia: bool

TRUE or FALSE depending on whether sorting was successful or not.

Príklady

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

print_r($array);

Súvisiace manuály

        Aktivity