Not quite true. Boolean is a distinct type in PHP. ! is a boolean operator,
so 0 first get convert into boolean (to false), then the expression is
evaluated. The difference between 0 and false is illustrated by the
following examples:
// Example A
if (!"Bush") {
echo "I am true";
}
else {
echo "I am false";
}
// Example B
if ("Bush" == 0) {
echo "I am zero";
}
else {
echo "I am not zero";
}
Example A prints "I am false", because a non-empty string converts to true.
Example B on the other hand, prints "I am zero" because "Bush" converts to
0. Thus, we get the following logic:
false == 0
0 == "Bush"
false != "Bush"
In linear algebra I think you would say "PHP variables do not form a vector
space."
Uzytkownik <xyzzy> napisal w wiadomosci
news:Na********************@comcast.com...
"Adams-Blake Company" <at************@adams-blaketakeout.com> wrote in
message news:vs************@news20.forteinc.com... Recently I made this mistake:
if (!0){
echo "I am true";
}
else {
echo "I am false";
}
It always evaluated to "true". What does (!0) equate to in plain
language? Why is it always true.
Al
Ones & Zeros, On or Off, True or False
!0 equates to not zero - which must then be 1 - or true
so, if (true) - is always true