How to handle a PHP switch with different types?

后端 未结 5 1426
栀梦
栀梦 2020-12-09 17:34

How can I make the switch respect data types ( is there a workaround better then if/else ) ?

  • $value = false; // should echo false
  • $value = null; // should ec
  • 5条回答
    •  独厮守ぢ
      2020-12-09 17:49

      Bare in mind that you're asking PHP to juggle types.

      If you see the PHP type comparison table you'll see that, for example, null and '' are loosly equivalent, ie null == ''.

    提交回复
    热议问题