duanaoou4105 2012-07-14 04:12
浏览 33
已采纳

php在php中排序长字符串

I have a directory listing that I need to sort. so far natsort works well except when a decimal is introduced. 009 comes after 009.1 I am trying to work on getting all the special char's out of the directory names and havent had issues with them so far. "http://10.1.1.1/manual/product/v02/secton 3/part 3.1 leveling/002.jpg" some get as long as 150 or so char's long. Since these are long strings with occasional decimals its not easy to get them properly sorted. I dont believe . are used any where except for decimals and the file extension

Every thing I have read so far ignores decimals. 0200 is before 100 in cases like that I would hope that specials would come after # and letters but appairently not.

  • 写回答

1条回答 默认 最新

  • douji6199 2012-07-14 04:20
    关注

    Given that you have sorting requirements that can't be met by any existing PHP functions, your best bet is to call usort() and write your own comparison function.

    Sample

    function cmp($a, $b)
    {
        return strcmp($a, $b); # replace with your own comparison logic
    }
    usort($array, 'cmp');
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 想问一下树莓派接上显示屏后出现如图所示画面,是什么问题导致的
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号