Easy Tutorial
❮ Func Filesystem Umask Func Misc Time Sleep Until ❯

PHP array_multisort() Function

Complete PHP Array Reference Manual

Example

Returns an array sorted in ascending order:


Definition and Usage

The array_multisort() function returns a sorted array. You can input one or multiple arrays. The function first sorts the first array, followed by the other arrays. If two or more values are the same, it will sort the next array.

Note: String keys will be preserved, but numeric keys will be re-indexed starting from 0 and incrementing by 1.

Note: You can set the sort order and sort type parameters after each array. If not set, each array parameter will use the default values.


Syntax

Parameter Description
array1 Required. Specifies the array.
sorting order Optional. Specifies the sort order. Possible values: SORT_ASC - Default. Sorts in ascending order (A-Z).<br> SORT_DESC - Sorts in descending order (Z-A).
sorting type Optional. Specifies the sort type. Possible values: SORT_REGULAR - Default. Sorts items in standard order (Standard ASCII, no type change).<br> SORT_NUMERIC - Treats each item as a number.<br> SORT_STRING - Treats each item as a string.<br> SORT_LOCALE_STRING - Treats each item as a string, based on the current locale (can be changed with setlocale()).<br> SORT_NATURAL - Treats each item as a string, using natural order similar to natsort().<br> SORT_FLAG_CASE - Can be combined (bitwise OR) with SORT_STRING or SORT_NATURAL to sort strings case-insensitively.
array2 Optional. Specifies the array.
array3 Optional. Specifies the array.

Technical Details

Return Value: Returns TRUE on success, FALSE on failure.
PHP Version: 4+
--- ---
Changelog: Sort types SORT_NATURAL and SORT_FLAG_CASE were added in PHP 5.4. <br> <br>Sort type SORT_LOCALE_STRING was added in PHP 5.3.
--- ---

More Examples

Example 1

Returns an array sorted in ascending order:

Example 2

How to sort when two values are the same:

Example 3

Using sort parameters:

Example 4

Merging two arrays and sorting them in descending numeric order:


❮ Func Filesystem Umask Func Misc Time Sleep Until ❯