How does PHP compare strings with comparison operators?

前端 未结 4 1769
清歌不尽
清歌不尽 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:27

    When both Strings are in Number format, PHP will convert the strings to numbers and convert the values.

    If you compare a number with a string or the comparison involves numerical strings, then each string is converted to a number and the comparison performed numerically. These rules also apply to the switch statement. The type conversion does not take place when the comparison is === or !== as this involves comparing the type as well as the value.

    Reference https://www.php.net/manual/en/language.operators.comparison.php

    Edit: formatting.

提交回复
热议问题