PHP array_multisort() Function
Last Updated : 17 Mar 2025
The array_multisort() is an built-in function in PHP. This function is used to sort multiple arrays at once or a multi-dimensional array with each dimension. This function was introduced in PHP 4.0.
Syntax
Parameters
| Parameter | Description | Required/Optional |
|---|---|---|
| array1 | Specifies an array. | compulsory |
| Sorting order | Specifies the sorting order. Possible values:
| Optional |
| Sorting type | Specifies the type to use when comparing elements. Possible values:
| Optional |
| array2 | Specifies an array. | Optional |
| array3 | Specifies an array. | Optional |
Return Type
The array_multisort()function returns true on success or false on failure.
Important note: String keys will be maintained, but numeric keys will be re-indexed, starting at 0 and increase by 1. If two members on comparing become equal, their relative order in the sorted array is undefined.
Example 1
Output:
Array
(
[0] =>dhoni
[1] =>ganguly
[2] =>sachin
[3] =>umesh
[4] =>virat
[5] =>yuvraj
)
Example 2
Output:
Array
(
[0] => Dell
[1] => Lenovo
)
Array
(
[0] => Asus
[1] => Acer
)
Example 3
Output:
Array
(
[0] => java
[1] =>php
[2] =>php
)
Array
(
[0] =>perl
[1] => python
[2] =>swift)
Example 4
Output:
Array
(
[0] => java
[1] =>php
[2] =>php
)
Array
(
[0] => python
[1] => swift
[2] =>perl
)
Next TopicPhp-array-natcasesort-function