Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

PHP array_multisort() Function

PHP array_multisort() Function

PHP Array ReferenceComplete PHP Array Reference Manual

Example

Return an array sorted in ascending order:

Run Example »


Definition and Usage

The array_multisort() function returns a sorted array. You can input one or more arrays. The function sorts the first array first, then the others; if two or more values are equal, it sorts by the next array.

**Note:** String keys will be preserved, but numeric keys will be reindexed starting from 0 and increasing by 1.

**Note:** You can set sorting order and sorting type parameters after each array. If not set, each array parameter uses the default values.


Syntax

array_multisort(

array1,sorting order,sorting type,array2,array3...

)

Parameters Description
array1 Required. Specifies the array.
sorting order Optional. Specifies the sorting order. Possible values:
  • SORT_ASC - Default. Sort in ascending order (A-Z).
  • SORT_DESC - Sort in descending order (Z-A).
  • | | *sorting type* | Optional. Specifies the sorting type. Possible values: | | *array2* | Optional. Specifies an array. | | *array3* | Optional. Specifies an array. |

    Technical Details

    Return Value: Returns TRUE on success, FALSE on failure.
    PHP Version: 4+
    Changelog: The sorting types SORT_NATURAL and SORT_FLAG_CASE were added in PHP 5.4.
     排序类型 SORT_LOCALE_STRING 是在 PHP 5.3 中新增的。 |
    

    More examples

    Example 1

    Return an array sorted in ascending order:

    Run Example »

    Example 2

    How to sort when two values are equal:

    Run Example »

    Example 3

    Using sorting parameters:

    Run Example »

    Example 4

    Merge two arrays and sort them in descending numeric order:

    Run Example »


    PHP Array ReferenceComplete PHP Array Reference Manual