zoukankan      html  css  js  c++  java
  • PHP natcasesort() 函数

    定义和用法

    natcasesort() 函数用"自然排序"算法对数组进行排序。键值保留它们原始的键名。

    在自然排序算法中,数字 2 小于 数字 10。在计算机排序算法中,10 小于 2,因为 "10" 中的第一个数字小于 2。

    该函数不区分大小写。高佣联盟 www.cgewang.com

    如果成功,该函数返回 TRUE,如果失败则返回 FALSE。

    语法

    natcasesort(array)
    参数描述
    array 必需。规定要进行排序的数组。

    实例

    <?php
    $temp_files = array("temp15.txt","Temp10.txt",
    "temp1.txt","Temp22.txt","temp2.txt");

    natsort($temp_files);
    echo "Natural order: ";
    print_r($temp_files);
    echo "<br />";

    natcasesort($temp_files);
    echo "Natural order case insensitve: ";
    print_r($temp_files);
    ?>

    上面代码将输出:

    Natural order:
    Array
    (
    [0] => Temp10.txt
    [1] => Temp22.txt
    [2] => temp1.txt
    [4] => temp2.txt
    [3] => temp15.txt
    )
    Natural order case insensitve:
    Array
    (
    [2] => temp1.txt
    [4] => temp2.txt
    [0] => Temp10.txt
    [3] => temp15.txt
    [1] => Temp22.txt
    )
  • 相关阅读:
    软件设计中的立足点
    Clojure基础
    团队凝聚力
    执行力与领导力
    工作与生活
    分离焦虑OR责任焦虑
    保持激情
    立足点
    论研发管理--开篇
    初级码农常犯错误
  • 原文地址:https://www.cnblogs.com/yc10086/p/12950412.html
Copyright © 2011-2022 走看看