PHPize Online / SQLize Online  /  SQLtest Online

A A A
Share      Blog   Popular

sort

Tags: PHP 5.x PHP 7.x PHP 8.x

sort — Sort an array in ascending order.

Description

sort(
    array &$array,
int $flags = SORT_REGULAR
): bool
Sorts array in place by values in ascending order.

Note:
If two members compare as equal, they retain their original order. Prior to PHP 8.0.0, their relative order in the sorted array was undefined.
This function assigns new keys to the elements in array. It will remove any existing keys that may have been assigned, rather than just reordering the keys.
Resets array's internal pointer to the first element.

Parameters

array
The input array.
flags
The optional second parameter flags can be any of the following values: SORT_REGULAR, SORT_NUMERIC, SORT_STRING, SORT_LOCALE_STRING, SORT_NATURAL, SORT_FLAG_CASE or SORT_STRING_CASE. If no flag is given, the sort is done in ascending order (bubble sort algorithm). The SORT_STRING_CASE flag is available since PHP 5.4.0.

Return Values

Always returns true.

sort - New snippets