php "", 0, '0', false == Analyzing

Today, a problem encountered in the project, give chestnuts:

if($_GET['is_has_idcard']==0 || $_GET['is_has_idcard']==1){

  echo 'This time I want to upload id';

}

if($_GET['marry_mes']!=''){

  echo 'This time I want to upload information marriage';

}

Such a judgment, when there is no traditional values when is_has_idcard, will echo this time I want to upload identity . Judgment on this wording in our process became a bug, learn about Baidu, the foundation still have to play ah. . .

================================================== ================================================== =======
which of the following is false:
a, 0 == "0";
B "" == "0"
C "" 0 ==
D == to false "0"
please explain these cases PHP What is the standard to which type of comparison is that?

answer:

A, True
B, fake
C, true
D, true
PHP is a weakly typed language, string, number, Boolean, and sometimes it can help you try to be smart transformation, this transformation is sometimes convenient, and sometimes bring annoyed .A: the number of characters and numbers can be transformed into each other, we all know this, B: 0 empty string and the string of course not the same .C: empty is 0, D: 0 character can be considered to be false.
as it creates a problem: because "" == 0, 0 == "0", "" == "0" is the B and B is false, MD, tangled.
here because PHP only made twenty-two conversion, so the above Although the reasoning is so tangled. but in fact, "" can not be directly translated into "0".
for this D, you're right, I think there is also a 0 character ah, but "0" can be converted to 0,0 it is false. feel unreasonable to say, the so-called truth is, people defined multi-test the actual write.

==============================================================================================================

Guess you like

Origin www.cnblogs.com/gyrgyr/p/11571904.html