Recently, I prefer to pick up the details, because these details are very helpful for code writing and bug finding, and can greatly improve the speed of project development.
Talk less, we begin to explain PHP Boolean.
First, the Boolean type is the basic data type of PHP, which is either true or false. Uppercase and lowercase are not differentiated.
If you need to convert other types to type bool, you can use (bool) or (Boolean) to convert.
Such as
echo true = = = (BOOL) -1;echo true = = = (Boolean) -1;echo true = = = (Boolean)-1;
Public Function Test_true () {$this->asserttrue ( -1 = = true);//-1=> true$this->asserttrue ("false" = = true);//"F Alse "= = True$this->asserttrue (" null "= = TRUE); "Null" = true$this->asserttrue ("0.0" = = true); "0.0" = True$this->asserttrue ((bool)-1), $this->asserttrue ((Boolean)-1); $this->asserttrue ( Boolean)-1);} Public Function Test_false () {$this->asserttrue (null = = False);//null = false$this->asserttrue (0 = = false);
//0 = false$this->asserttrue (0.0 = = false); 0.0 = False$this->asserttrue ("" = = False); "" = = False$this->assertfalse ("" = = False); "" = true}
These are the two simple test cases that I wrote. All of them asserted success.
-1 = = True results are true.
Similarly, NULL = = False results are also true.
is the non-strict type of comparison.
There's also a need to be aware of bool, Boolean, Boolean. In fact, there should be no big difference. But always keep in mind that it's just the basic data type, and there's no class concept ...