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 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?