So, here is this page on the php site, which shows the result of comparing different values:
http://php.net/manual/en/types.comparisons.php
This is a useful link, but I would prefer not to visit this page every time I want to make sure that I am doing type comparisons correctly. So my question is:
Is there any basic philosophy / logic of type comparison logic in PHP?
For example, I see that for free comparison:
but since then he gets a little hairy trying to set a pattern.
For casting directly to a logical, this works.
Then these rules for comparing variables of the same type:
For a variable of different types, the type that is higher in the above list is converted to one that is lower than the comparison.
=== !== , , ===, .
===
!==
- , ===, , .
$a = array("a"=>1, "b"=>2); $b = array("b"=>2, "a"=>1); $a == $b; // true $a === $b; // false
empty() !(bool)$var
empty()
!(bool)$var
Array
__toString
ArrayAccess
=== : , TRUE === TRUE, "1" === "1", "1" !== 1 ..
TRUE === TRUE
"1" === "1"
"1" !== 1
== , , , . , , . , , :
==
: A == B TRUE , A B , . , array() == NULL TRUE, array() NULL , array() == 0 - FALSE, , .
A == B
TRUE
A
B
array() == NULL
array()
NULL
array() == 0
FALSE
, , ( ) .
, (, "1" == "1" ..), .
"1" == "1"
, , "php" == 0 TRUE ( , 0): PHP "php" , , 0 TRUE.
"php" == 0
0
"php"
: ! , , True , False - , PHP: D
-, true. , 1, 1.123, array("value") .. true.
true
1
1.123
array("value")
(.. -), false. , 0, 0.0, array() ..
false
0.0
PHP. . . Perl, C Javascript, .
, .
. .
( ) php : , , , .
0 "0", , false ( ). : , false, , false, 0, 0.
null array() . , (), , true. , , is_null, false. , , array(), array(), '', null. , is_null() == null === null , , . Null is_array(), . is_array(), . , , null array().
null
'0'
strict
return ($something);
$something
, C: , , .
.
- '0', ( ) , . array(0) .
array(0)
(=== !==) . , , , .
: