Current Location: Home> Function Categories> array_multisort

array_multisort

Sort multiple arrays or multi-dimensional arrays
Name:array_multisort
Category:Array
Programming Language:php
One-line Description:Sort multiple arrays or multi-dimensional arrays.

Definition and usage

array_multisort() function returns a sorted array. You can enter one or more arrays. The function sorts the first array first, followed by the other arrays, and if two or more values ​​are the same, it sorts the next array.

Note: The string key name will be retained, but the numeric key name will be reindexed, starting at 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 uses the default value.

grammar

 array_multisort ( array1 , sorting order , sorting type , array2 , array3 ... )
parameter describe
array1 Required. Specify array.
sorting order

Optional. Specify the order of arrangement. Possible values:

  • SORT_ASC - Default. Order in ascending order (AZ).
  • SORT_DESC - Order in descending order (ZA).
sorting type

Optional. Specify the sorting type. Possible values:

  • SORT_REGULAR - Default. Arrange each item in a regular order (Standard ASCII, without changing the type).
  • SORT_NUMERIC - Process each item as a number.
  • SORT_STRING - Handle each item as a string.
  • SORT_LOCALE_STRING - Handle each item as a string, based on the current locale setting (can be changed via setlocale()).
  • SORT_NATURAL - Handle each item as a string, using a natural sort like natsort().
  • SORT_FLAG_CASE - Strings can be sorted in conjunction with (bit-by-bit or) SORT_STRING or SORT_NATURAL, and are case-insensitive.
array2 Optional. Specify array.
array3 Optional. Specify array.

illustrate

array_multisort() function sorts multiple arrays or multidimensional arrays.

The arrays in the parameters are treated as columns of a table and sorted by rows - this is similar to the functionality of the ORDER BY clause of SQL. The first array is the main array to be sorted. If the rows (values) in the array are compared to the same, they will be sorted according to the size of the corresponding value in the next input array, and so on.

The first parameter is an array, and each subsequent parameter may be an array, or one of the following sort order flags (the sort flag is used to change the default sort order):

  • SORT_ASC - Default, sorted in ascending order. (AZ)
  • SORT_DESC - In descending order. (ZA)

You can then specify the sort type:

  • SORT_REGULAR - Default. Arrange each item in a regular order.
  • SORT_NUMERIC - Order each item in numerical order.
  • SORT_STRING - Order each item alphabetically.
Similar Functions
Popular Articles