What sort algorithm does PHP use?

后端 未结 3 353
刺人心
刺人心 2020-12-05 17:22

Internally speaking, which algorithm(s) does PHP use to implement the various sort functions it offers? It seems like the usort variants might use a different algorithm than

3条回答
  •  我在风中等你
    2020-12-05 18:07

    For sorting, PHP uses an implementation of quicksort that can be found in Zend/zend_qsort.c, which takes a comparison function and an array of elements. The default comparison function for sort() is defined in ext/standard/array.c and is called php_array_data_compare(). So basically, it's the same algorithm for all sorting functions, except that they take different comparison functions.

提交回复
热议问题