PHP標準排序和自然排序

2021-10-02 04:23:34 字數 830 閱讀 5864

自然排序演算法中,數字 2 小於 數字 10。

在計算機標準排序演算法中,10 小於 2,因為 「10」 中的第乙個數字小於 2。

舉例**:

$temp_files

=array

("temp15.txt"

,"temp10.txt"

,"temp1.txt"

,"temp22.txt"

,"temp2.txt");

sort

($temp_files);

echo

"標準排序:"

;print_r

($temp_files);

echo""

;natsort

($temp_files);

echo

"自然排序:"

;print_r

($temp_files

);

輸出結果得到如下:

標準排序:

array

([0] => temp1.txt

[1] => temp10.txt

[2] => temp15.txt

[3] => temp2.txt

[4] => temp22.txt

)自然排序:

array

([0] => temp1.txt

[3] => temp2.txt

[1] => temp10.txt

[2] => temp15.txt

[4] => temp22.txt

)

MYSQL資料排序(九)自然排序

假設我們有乙個名為items的表,包含兩列 id和item no。要建立items表,我們使用create table語句,sql語句如下 create table ifnot exists items id int auto increment primary key,item no varcha...

php排序演算法 氣泡排序和快速排序

總是對這兩種排序特別迷糊,今天趁活不多,認真看了下,也算對自己有個交代吧 第一 氣泡排序 預設從小到大排序 若從小到大則第二個引數為true function bubbling sort arr,state false else return arr 上午寫了冒泡法,整體思路還是很清晰的,但是到快速...

自然合併排序

自然合併排序演算法是對合併排序演算法的一種改進。設 a 0 n 1 是無序陣列,用一次對陣列a的掃瞄可以找出其中 自然排好序的子陣列,然後將相鄰的排好序的子陣列段兩 兩合併,繼續合併相鄰排好序的子陣列段,直至將整個數 組排好序。code include include using namespace...