Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What algorithm does arsort use?

Tags:

php

The doc doesnt seem to tell us what algorithm is used for array sorting. So what algorithm does the function arsort use? In otherwords, does it use merge sort, quick sort?

Code taken from doc:

<?php
$fruits = array("d" => "lemon", "a" => "orange", "b" => "banana", "c" => "apple");
arsort($fruits);
foreach ($fruits as $key => $val) {
    echo "$key = $val\n";
}

Output:

a = orange
d = lemon
b = banana
c = apple
like image 600
Goaler444 Avatar asked Dec 06 '25 02:12

Goaler444


1 Answers

Like all PHP sort functions, the quicksort algorithm is used

See the Note in the manual:

Note: Like most PHP sorting functions, sort() uses an implementation of » Quicksort.

like image 139
Mark Baker Avatar answered Dec 07 '25 16:12

Mark Baker