Home >>PHP Array Functions >PHP array_multisort() Function
PHP array_multisort() Function is used to returns a sorted array. You can assign one or more arrays .The first array is sorted by the function, and the other arrays obey, then, if two or more values are the same, the next array is sorted, etc ..
Syntax:
array_multisort(array1, sortorder, sorttype, array2, array3, ...)
Parameter | Description |
---|---|
array1 | This is required parameter. This parameter specifies an array. |
array2 | This is optional parameter. This parameter specifies an array. |
array3 | This is optional parameter. This parameter specifies an array. |
Here, is an example of array_multisort() Function in PHP:
<html> <body> <?php $a=array("cat","camel","Horse","Bear","Zebra"); $b=array("rat","rabbit","cockroach","pigeons","snake"); array_multisort($b); print_r($b); ?> </body> </html>
Array ( [0] => cockroach [1] => pigeons [2] => rabbit [3] => rat [4] => snake )
Example 2:
<html> <body> <?php $a=array("camel","horse","pigeons","snake"); array_multisort($a); print_r($a); ?> </body> </html>
Array ( [0] => camel [1] => horse [2] => pigeons [3] => snake )