The table below shows the role of PHP types and comparison operators when they are loosely and rigorously compared. The supplemental material is also relevant to the relevant section of the type-juggling. At the same time, a large number of user comments and»blueshoes work also provides help for this material.
Before using these tables, you need to understand the types of variables and their meanings. For example," A" is a string and a whole number is an integer. FALSE
is a boolean value and "false" is a string.
Note:
HTML forms do not pass integers, floating-point numbers, or Boolean values, they only pass strings. To detect if a string is not a number, you can use the is_numeric () function.
Note:
When a variable is not defined $x , usage such as if ($x) results in a E_NOTICE
level of error. Therefore, you might consider initializing the variable with the empty () or isset () function.
using PHP functions to $x compare variables
An expression |
GetType () |
empty () |
is_null () |
isset () |
Boolean: if ($x) |
$x = ""; |
String |
TRUE |
FALSE |
TRUE |
FALSE |
$x = null; |
Null |
TRUE |
TRUE |
FALSE |
FALSE |
var $x; |
Null |
TRUE |
TRUE |
FALSE |
FALSE |
$xis undefined |
Null |
TRUE |
TRUE |
FALSE |
FALSE |
$x = Array (); |
Array |
TRUE |
FALSE |
TRUE |
FALSE |
$x = false; |
Boolean |
TRUE |
FALSE |
TRUE |
FALSE |
$x = true; |
Boolean |
FALSE |
FALSE |
TRUE |
TRUE |
$x = 1; |
Integer |
FALSE |
FALSE |
TRUE |
TRUE |
$x = 42; |
Integer |
FALSE |
FALSE |
TRUE |
TRUE |
$x = 0; |
Integer |
TRUE |
FALSE |
TRUE |
FALSE |
$x =-1; |
Integer |
FALSE |
FALSE |
TRUE |
TRUE |
$x = "1"; |
String |
FALSE |
FALSE |
TRUE |
TRUE |
$x = "0"; |
String |
TRUE |
FALSE |
TRUE |
FALSE |
$x = "1"; |
String |
FALSE |
FALSE |
TRUE |
TRUE |
$x = "PHP"; |
String |
FALSE |
FALSE |
TRUE |
TRUE |
$x = "true"; |
String |
FALSE |
FALSE |
TRUE |
TRUE |
$x = "false"; |
String |
FALSE |
FALSE |
TRUE |
TRUE |
PHP Type Comparison Table