PHP數組的“自然”排序_PHP教程

來源:互聯網
上載者:User
natsort
(PHP 4, PHP 5)

natsort — 用“自然排序”演算法對數組排序

說明
bool natsort ( array &$array )
本函數實現了一個和人們通常對字母數字字串進行排序的方法一樣的排序演算法並保持原有鍵/值的關聯,這被稱為“自然排序”。本演算法和通常的電腦字串排序演算法(用於 sort())的區別見下面樣本。

參數
array
輸入的 array。

傳回值
成功時返回 TRUE, 或者在失敗時返回 FALSE.

Example #1 natsort() examples demonstrating basic usage

$array1 = $array2 = array("img12.png", "img10.png", "img2.png", "img1.png");

asort($array1);
echo "Standard sorting\n";
print_r($array1);

natsort($array2);
echo "\nNatural order sorting\n";
print_r($array2);
?>
以上常式會輸出:

Standard sorting
Array
(
[3] => img1.png
[1] => img10.png
[0] => img12.png
[2] => img2.png
)

Natural order sorting
Array
(
[3] => img1.png
[2] => img2.png
[1] => img10.png
[0] => img12.png
)

http://www.bkjia.com/PHPjc/477517.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/477517.htmlTechArticlenatsort (PHP 4, PHP 5) natsort 用自然排序演算法對數組排序 說明 bool natsort ( array $array ) 本函數實現了一個和人們通常對字母數字字串進行排序的...

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.