Name

array_multisort

Synopsis

bool array_multisort(array array1[, SORT_ASC|SORT_DESC
    [, SORT_REGULAR|SORT_NUMERIC|SORT_STRING]] [, array array2[, SORT_ASC|SORT_DESC
    [, SORT_REGULAR|SORT_NUMERIC|SORT_STRING]], ...])

Used to sort several arrays simultaneously, or to sort a multidimensional array in one or more dimensions. The input arrays are treated as columns in a table to be sorted by rows—the first array is the primary sort. Any values that compare the same according to that sort are sorted by the next input array, and so on.

The first argument is an array; following that, each argument may be an array or one of the following order flags (the order flags are used to change the default order of the sort):

SORT_ASC (default)

Sort in ascending order

SORT_DESC

Sort in descending order

After that, a sorting type from the following list can be specified:

SORT_REGULAR (default)

Compare items normally

SORT_NUMERIC

Compare items numerically

SORT_STRING

Compare items as strings

The sorting flags apply only to the immediately preceding array, and they revert to SORT_ASC and SORT_REGULAR before each new array argument.

This function returns true if the operation was successful and false otherwise.

Get Programming PHP, 3rd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.