Home >Backend Development >PHP Tutorial >Can PHP achieve congruence in switch?
<code> switch($value){ case null: echo 'null'; break; case '': echo '空'; break; } </code>
The problem now is that when $value = '', switch will enter the first case.
Can we achieve congruent judgment and let the switch enter the second case?
<code> switch($value){ case null: echo 'null'; break; case '': echo '空'; break; } </code>
The problem now is that when $value = '', switch will enter the first case.
Can we achieve congruent judgment and let the switch enter the second case?
You can change your mind and look at the code
<code>switch(true) { case null === $value : echo 'null'; break; case '' === $value: echo '空'; break; }</code>
No, switch does a loose comparison.
What you said above is correct. Change your thinking