dq_609586475 2016-11-09 22:28
浏览 11
已采纳

在PHP中,为什么字符串“1874S-O.jpg”不大于“1874S.jpg”?

I was attempting to sort some strings in an array alphabetically. The strings were file names I grabbed from a directory using glob. At first, I thought glob was incorrectly sorting the file names. I tried sort, and the same thing happened: 1874S-O.jpg came before 1874S.jpg

Finally, I compared them with

var_dump("11-09-2016/1874S/1874S-O.jpg" > "11-09-2016/1874S/1874S.jpg");

which returned bool(false). Any ideas why the longer string would not be greater than the shorter string and would also not come after the shorter string alphabetically?

  • 写回答

2条回答 默认 最新

  • dongque20030402 2016-11-09 22:32
    关注

    Because . is greater than -.

    Those are the first non-equal characters in your strings.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥33 找熟练码农写段Pyhthon程序
  • ¥100 怎么让数据库字段自动更新
  • ¥15 antv g6 力导向图布局
  • ¥15 quartz框架,No record found for selection of Trigger with key
  • ¥15 锅炉建模+优化算法,遗传算法优化锅炉燃烧模型,ls-svm会搞,后面的智能算法不会
  • ¥20 MATLAB多目标优化问题求解
  • ¥15 windows2003服务器按你VPN教程设置后,本地win10如何连接?
  • ¥15 求一阶微分方程的幂级数
  • ¥15 关于#线性回归#的问题:【统计】回归系数要转化为相关系数才能进行Fisher' Z转化吗(相关搜索:回归模型)
  • ¥100 使用matlab解决含分段变量的优化问题