make switch use === comparison not == comparison In PHP

后端 未结 15 2128
一向
一向 2020-11-28 07:09

Is there anyway to make it so that the following code still uses a switch and returns b not a? Thanks!

$var = 0;
switch($var) {
            


        
15条回答
  •  抹茶落季
    2020-11-28 07:17

    I had the same problem in a switch with string containing numbers ("15.2" is equal to "15.20" in a switch for php)

    I solved the problem adding a letter before the text to compare

    $var = '15.20';
    switch ('#'.$var) {
        case '#15.2' :
          echo 'wrong';
        break;
        case '#15.20' :
          echo 'right';
        break;
    }
    

提交回复
热议问题