Page 1 of 1

[SOLVED] ! (NOT) Operator not printing 0 !

Posted: Wed Mar 30, 2005 12:52 am
by anjanesh

Code: Select all

$var = 0;
echo !var; // Ouputs 1
$var = 1;
echo !var; // Does not Ouput 0 - I want it to
I guess 0 is not printed because its value becomes false ?
Any way to output 0 without using conditional statements ?
Thanks

Posted: Wed Mar 30, 2005 1:14 am
by feyd

Code: Select all

echo ((int) !1);

Posted: Wed Mar 30, 2005 1:30 am
by anjanesh
Thanks. This is solved.
BTW, why doesnt type casting work the other way round as in C/C++ ?
int(!1)
PHP is trying the search for function int instead of typecasting it.
All other languages seem to work with int()

Posted: Wed Mar 30, 2005 10:03 am
by feyd
C can do either way. The major reason would probably be that PHP doesn't have typing like they do.