David Richied David Richied - 1 year ago 64
PHP Question

In PHP, why is the string "1874S-O.jpg" not greater than "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:

came before

Finally, I compared them with

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

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

Answer Source

Because . is greater than -.

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download