How to compare 2 strings alphabetically in PHP?

前端 未结 5 985
青春惊慌失措
青春惊慌失措 2021-02-04 23:34

What the title says. Specifically if I have

$array1[\'name\'] = \'zoo\';
$array2[\'name\'] = \'fox\';

How can I determine that alphabetically <

5条回答
  •  情深已故
    2021-02-04 23:46

    Use strcmp. If the first argument to strcmp is lexicographically smaller to the second, then the value returned will be negative. If both are equal, then it will return 0. And if the first is lexicograpically greater than the second then a positive number will be returned.

    nb. You probably want to use strcasecmp(string1,string2), which ignores case...

提交回复
热议问题