Ask a Question related to PHP Development, Design and Development.
-
Adams-Blake Company #1
if (!0) means what?
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
Adams-Blake Company Guest
-
SWC,SWF Means
What is the abbrevation of .SWC , .SWF formats. please any one give me reply -
what does (gray#) means
hi there, from a client we received some grayscale images (just black and white scannings I think), that when opened in Photoshop 7 inside the... -
chkconfig: - 60 20 ; what does means?
I found following script line in /etc/rc.d/init.d/nfs chkconfig: - 60 20 someone tell me what does above line means? I think start priority 60... -
Can you tell me what this coding means?
One of our employees received an email (spam) that contained some code that didn't make sense to us. In the source code you will see the words... -
What means Protected WithEvents ?
The keyword 'protected' is an access modifier. You can get started understanding what is going on by opening your MSDN Library, look for the term... -
Re: if (!0) means what?
"Adams-Blake Company" <atakeoutcanton@adams-blaketakeout.com> wrote in
message news:vsvu58f0s0hq9c@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
Guest
-
J0hn Sm1th #3
Re: if (!0) means what?
Adams-Blake Company wrote:
Have a look at: [url]http://www.blueshoes.org/en/developer/php_cheat_sheet/[/url]> 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
>
Looks like '0' always evaluates to false, so essentially you're just
returning 'not false' which is always true ;)
J0hn Sm1th Guest
-
Adams-Blake Company #4
Re: if (!0) means what?
<xyzzy> wrote:
I had not thought of it in that way.>
> "Adams-Blake Company" <atakeoutcanton@adams-blaketakeout.com> wrote in
> message news:vsvu58f0s0hq9c@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
Thanks. And thanks to the person who posted the URL to the Cheat Sheet. Very
helpful.
Al
Adams-Blake Company Guest
-
Chung Leong #5
Re: if (!0) means what?
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:NaadnYu0CvoVZ1KiRVn-vw@comcast.com...language?>
> "Adams-Blake Company" <atakeoutcanton@adams-blaketakeout.com> wrote in
> message news:vsvu58f0s0hq9c@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>> > 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
>
>
>
>
Chung Leong Guest
-
Re: if (!0) means what?
"Chung Leong" <chernyshevsky@hotmail.com> wrote in message
news:CsidnY5G26w9hE2iRVn-sQ@comcast.com...operator,> Not quite true. Boolean is a distinct type in PHP. ! is a booleantrue.> 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 tovector> 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 aI disagree.> space."
>
> Uzytkownik <xyzzy> napisal w wiadomosci
> news:NaadnYu0CvoVZ1KiRVn-vw@comcast.com...> language?> >
> > "Adams-Blake Company" <atakeoutcanton@adams-blaketakeout.com> wrote in
> > message news:vsvu58f0s0hq9c@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> >> > > 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
> >
Yes, strings can evaluate to true and false if they are null or !null
However, zero is numeric until you convert it to Boolean by using the !
<?
$a = 0;
echo "a = $a\n";
echo "!a = " . !$a . "\n";
echo "is_bool(a) ".($a ? "true":"false") . "\n";
echo "is_bool(!a) ".(!$a ? "true":"false") . "\n";
?>
*** produces ***
a = 0
!a = 1
is_bool(a) =false
is_bool(!a) =true
Guest



Reply With Quote

