How to compare 2 strings alphabetically in PHP?

前端 未结 5 983
青春惊慌失措
青春惊慌失措 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:42

    I'm a little late (then again I wasn't a programmer yet in 2009 :-) No one mentioned this yet, but you can simply use the operators which you use on number as well.

    < > <= >= == != and more

    For example:

    'a' > 'b' returns false

    'a' < 'b' returns true

    http://php.net/manual/en/language.operators.comparison.php

    IMPORTANT

    There is a flaw, which you can find in the comments below.

提交回复
热议问题