How does PHP compare strings with comparison operators?

前端 未结 4 1772
清歌不尽
清歌不尽 2020-12-02 00:14

I\'m comparing strings with comparison operators.

I needs some short of explanations for the below two comparisons and their result.

if(\'ai\' >          


        
4条回答
  •  感动是毒
    2020-12-02 00:23

    PHP will compare alpha strings using the greater than and less than comparison operators based upon alphabetical order.

    • In the first example, ai comes before i in alphabetical order so the test of > (greater than) is false - earlier in the order is considered 'less than' rather than 'greater than'.

    • In the second example, ia comes after i alphabetical order so the test of > (greater than) is true - later in the order being considered 'greater than'.

提交回复
热议问题