Previous | Home | Next |
array_multisort()
The array_multisort() function returns a sorted array. You can assign one or more arrays. The function sorts the first array, and the another arrays follow, then, if two or more values are the same, it sorts the next array, and so on.
Syntax:array_multisort(array1,sorting order,sorting type,array2,array3...)
In above syntax, "array1" specifies an array, "sorting order" specifies the sorting order and values are as follows:
- SORT_ASC: Sort in ascending order and is default order (A-Z)
- SORT_DESC: Sort in descending order (Z-A)
- SORT_REGULAR: Compare elements normally (Standard ASCII) and is default type
- SORT_NUMERIC: Compare elements as numeric values
- SORT_STRING: Compare elements as string values
- SORT_LOCALE_STRING: Compare elements as string, based on the current locale (can be changed using setlocale())
- SORT_NATURAL: Compare elements 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
Example:
<?php $array1=array("Apple","Banana","Orange"); $array2=array("Onion","Tomato","Potato"); array_multisort($array1,$array2); print_r($array1); print_r($array2); ?>
Output:
Previous | Home | Next |