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条)

报告相同问题?