true - false
Code:
new test = 1Code:
new test2 = 0I mean, you can wirte 1 instead of true and 0 instead of false, yes? |
Re: true - false
Basically every number except 0, casted to boolean, returns 1 (including negative numbers).
In your code, it will be the same. But usually boolean variables have "bool:" tag to show that they are booleans, not integers, but that isn't necessary. |
Re: true - false
Bools and integers are the same. While bools are for better readability, integers can have more options than two, so the usage is situational. If you are sure you will only have the variable to describe a state ( true, false ), you can use bools. If you are however able to put more than two states in one variable, use integers. What I mean is:
PHP Code:
PHP Code:
PHP Code:
|
Re: true - false
Quote:
So, for example: Code:
When you use !, it opposites the bits in the value, so any non-zero number becomes 0 and 0's become 1. So: Code:
When you use it twice, it just does the operation twice. The result is forcing a value to be a boolean constant. Code:
|
Re: true - false
Ah, I think I got it now, thanks. I've always wondered what exactly is the purpose of "!!".
|
Re: true - false
Quote:
|
Re: true - false
Quote:
|
Re: true - false
Quote:
Code:
(!!(0) == true) // true |
Re: true - false
Quote:
|
Re: true - false
Quote:
Quote:
|
| All times are GMT -4. The time now is 06:07. |
Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.