PHP - Function array_multisort()


Advertisements


Syntax

array_multisort(array1,sorting order,sorting type,array2...);

Definition and Usage

This can be used to sort several arrays at once, or a multi-dimensional array by one or more dimensions.

Parameters

Parameter Description
array1 Required. Specifies an array
Sort 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 type to use, when comparing elements. Possible values −

  • SORT_REGULAR Default. Compare elements normally
  • SORT_NUMERIC Compare elements as numeric values
  • SORT_STRING Compare elements as string values
array2 Optional. Specifies an array

Return Values

Returns TRUE on success or FALSE on failure.

Example

Try out following example −

<?php
   $array1 = array("10", 100, 100, "a");
   $array2 = array(1, 3, "2", 1);
   
   array_multisort($array1, $array2);
   print_r($array1);
   print_r($array2);
?> 

This will produce the following result −

Array ( [0] => 10 [1] => a [2] => 100 [3] => 100 ) Array ( [0] => 1 [1] => 1 [2] => 2 [3] => 3 )

php_function_reference.htm