Menu Samaritan's Purse

ARRAY_MULTISORT

Sort multiple or multi-dimensional arrays

SYNTAX

array_multisort ( array &$array1 [, mixed $array1_sort_order = SORT_ASC [, mixed $array1_sort_flags = SORT_REGULAR [, mixed $... ]]] ) : bool

PARAMETERS

array1

An array being sorted.

array1_sort_order

The order used to sort the previous array argument.

SORT_ASC sort ascending
SORT_DESC sort descending

This argument can be swapped with array1_sort_flags or omitted entirely, in which case SORT_ASC is assumed.

array1_sort_flags

The sort options for the previous array argument.

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. It uses the locale, which can be changed using setlocale()
SORT_NATURAL compare items as strings using "natural ordering" like natsort()
SORT_FLAG_CASE can be combined (bitwise OR) with SORT_STRING or SORT_NATURAL to sort strings case-insensitively

This argument can be swapped with array1_sort_order or omitted entirely, in which case SORT_REGULAR is assumed.

...

More arrays, optionally followed by sort order and flags. Only elements corresponding to equivalent elements in previous arrays are compared. In other words, the sort is lexicographical.

RETURN

Returns TRUE on success or FALSE on failure.

EXAMPLES

ARRAY1

Array
(
    [0] => B
    [1] => a
    [2] => b
    [3] => c
)

ARRAY1_SORT_ORDER | SORT_ASC

Array
(
    [0] => B
    [1] => a
    [2] => b
    [3] => c
)

ARRAY1_SORT_ORDER | SORT_DESC

Array
(
    [0] => c
    [1] => b
    [2] => a
    [3] => B
)

ARRAY1_SORT_FLAGS | SORT_REGULAR

Array
(
    [0] => B
    [1] => a
    [2] => b
    [3] => c
)

ARRAY1_SORT_FLAGS | SORT_NUMERIC

Array
(
    [0] => b
    [1] => B
    [2] => c
    [3] => a
)

ARRAY1_SORT_FLAGS | SORT_STRING

Array
(
    [0] => B
    [1] => a
    [2] => b
    [3] => c
)

ARRAY1_SORT_FLAGS | SORT_LOCALE_STRING

Array
(
    [0] => a
    [1] => b
    [2] => B
    [3] => c
)

ARRAY1_SORT_FLAGS | SORT_NATURAL

Array
(
    [0] => B
    [1] => a
    [2] => b
    [3] => c
)

ARRAY1_SORT_FLAGS | SORT_FLAG_CASE

Array
(
    [0] => a
    [1] => b
    [2] => B
    [3] => c
)

ARRAY2

Array
(
    [0] => B
    [1] => a
    [2] => b
    [3] => c
)
Array
(
    [0] => 2
    [1] => 1
    [2] => 3
    [3] => 4
)

ARRAY2_SORT_ORDER | SORT_ASC

Array
(
    [0] => B
    [1] => a
    [2] => b
    [3] => c
)
Array
(
    [0] => 2
    [1] => 1
    [2] => 3
    [3] => 4
)

ARRAY2_SORT_ORDER | SORT_DESC

Array
(
    [0] => c
    [1] => b
    [2] => a
    [3] => B
)
Array
(
    [0] => 4
    [1] => 3
    [2] => 1
    [3] => 2
)

ARRAY2_SORT_FLAGS | SORT_REGULAR

Array
(
    [0] => B
    [1] => a
    [2] => b
    [3] => c
)
Array
(
    [0] => 2
    [1] => 1
    [2] => 3
    [3] => 4
)

ARRAY2_SORT_FLAGS | SORT_NUMERIC

Array
(
    [0] => a
    [1] => B
    [2] => b
    [3] => c
)
Array
(
    [0] => 1
    [1] => 2
    [2] => 3
    [3] => 4
)

ARRAY2_SORT_FLAGS | SORT_STRING

Array
(
    [0] => B
    [1] => a
    [2] => b
    [3] => c
)
Array
(
    [0] => 2
    [1] => 1
    [2] => 3
    [3] => 4
)

ARRAY2_SORT_FLAGS | SORT_LOCALE_STRING

Array
(
    [0] => a
    [1] => b
    [2] => B
    [3] => c
)
Array
(
    [0] => 1
    [1] => 3
    [2] => 2
    [3] => 4
)

ARRAY2_SORT_FLAGS | SORT_NATURAL

Array
(
    [0] => B
    [1] => a
    [2] => b
    [3] => c
)
Array
(
    [0] => 2
    [1] => 1
    [2] => 3
    [3] => 4
)

ARRAY2_SORT_FLAGS | SORT_FLAG_CASE

Array
(
    [0] => a
    [1] => B
    [2] => b
    [3] => c
)
Array
(
    [0] => 1
    [1] => 2
    [2] => 3
    [3] => 4
)

SWAP | ARRAY1_SORT_ORDER ARRAY1_SORT_FLAGS

Array
(
    [0] => 0
    [1] => 1
)

SWAP | ARRAY1_SORT_FLAGS ARRAY1_SORT_ORDER

Array
(
    [0] => 0
    [1] => 1
)

SWAP | ARRAY2_SORT_ORDER ARRAY2_SORT_FLAGS

Array
(
    [0] => 0
    [1] => 1
)
Array
(
    [0] => 0
    [1] => 1
)

SWAP | ARRAY2_SORT_FLAGS ARRAY2_SORT_ORDER

Array
(
    [0] => 0
    [1] => 1
)
Array
(
    [0] => 0
    [1] => 1
)

ARRAY_COLUMN

Array
(
    [0] => Array
        (
            [volume] => 98
            [edition] => 2
        )

    [1] => Array
        (
            [volume] => 86
            [edition] => 1
        )

    [2] => Array
        (
            [volume] => 86
            [edition] => 6
        )

    [3] => Array
        (
            [volume] => 85
            [edition] => 6
        )

    [4] => Array
        (
            [volume] => 67
            [edition] => 2
        )

    [5] => Array
        (
            [volume] => 67
            [edition] => 7
        )

)

ARRAY_MAP

Array
(
    [0] => Alpha
    [1] => atomic
    [2] => bank
    [3] => Beta
)

PHP