Jump to content

if (!'0') what does it do?


Gayner

Recommended Posts

This is my simple code.

 

FIrst of all Hi everyone :)

 

I am a little lost of some php if function here:

 

if (!$ibforums->member['view_img'])
            {
                echo "OH HELLO!";
            }

 

So My Variable $ibforums->member['view_img'] in my database means = 1

 

So If I replace $ibforums->member['view_img'] to 1 it would be:

 

if (!1)

{

echo "HELLO!";

}

 

I dont get it?

 

What is the ! for ?

 

Thanks in advance.

 

so if it's !0 it means dont show?

Link to comment
https://forums.phpfreaks.com/topic/167924-if-0-what-does-it-do/
Share on other sites

the "!" in front very simply means NOT...

 

so for if(!1), or any other non-zero number, the if statement will always evaluate to false...

 

with if(!0), it will evaluate to true...

 

so i guess in this sense it kinda just means the opposite, where 0 = false, and any non-zero number true, and the ! just evaluates to the opposite of that...

 

hope this helps... and i wrote that right, lol...

Link to comment
https://forums.phpfreaks.com/topic/167924-if-0-what-does-it-do/#findComment-885699
Share on other sites

the "!" in front very simply means NOT...

 

so for if(!1), or any other non-zero number, the if statement will always evaluate to false...

 

with if(!0), it will evaluate to true...

 

so i guess in this sense it kinda just means the opposite, where 0 = false, and any non-zero number true, and the ! just evaluates to the opposite of that...

 

hope this helps... and i wrote that right, lol...

 

What if I put a !2 what would that do?

Link to comment
https://forums.phpfreaks.com/topic/167924-if-0-what-does-it-do/#findComment-885701
Share on other sites

if statement requires a boolean value: true or false. 0 and 1 are integers and are automatically converted, as well as all other types you'll try to use here. The manual shows the conversion rules: what is converted to false and what - to true: Boolean type. We can see that "0" is converted to false and any other number - to "true".

Link to comment
https://forums.phpfreaks.com/topic/167924-if-0-what-does-it-do/#findComment-885764
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.