This is a discussion on RE: [PHP] Alternate Colors in Rows ($r=!$r) within the PHP General forums, part of the PHP Programming Forums category; [snip] The value of the expression is the value assigned. Since the ! operator will always return a boolean then the ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
[snip]
The value of the expression is the value assigned. Since the ! operator will always return a boolean then the assigned value is going to be a boolean. So $r will always contain a boolean for the purposes of the ternary operation. [/snip] And it also work if the statement is not ternary |
|
|||
|
[snip]
The value of the expression is the value assigned. Since the ! operator will always return a boolean then the assigned value is going to be a boolean. So $r will always contain a boolean for the purposes of the ternary operation. And it also work if the statement is not ternary [/snip] And now for a little clarity. THIS is not a ternary if($r = !$r) it is a conditional test. ? foo : bar; ....is the ternary operation. Just wanted to clean up the usage there. |
|
|||
|
[snip]
if($r = !$r) [/snip] And I hit send before I finished my thought process oh my goodness isn't it five o'clock yet and why do all of these people keep coming by my office distracting me from getting something useful done like replying the PHP list and why doesn't someone bring me a beer? if($r = !$r) is a conditional check that most folks would read as follows; if the assignment of $r to !$r occurs the statement is TRUE. Since PHP is loosely typed we all know that an assignment will occur regardless of what is assigned. That why we use additional operators to determine the TRUEness of a statement; if($r == !$r) or if($r === !$r) That is why we code conditional checks (if we're smart) by putting the constant on the left hand side of the check to reduce/locate typographical errors when coding conditional checks; if(1 == $foo), because if we assign $foo to 1 the compiler will throw an error and we can fix it pretty quickly. This is one of those special cases where this logic gets thrown out. I am going to see if the same thing will work in C++ because I am pretty sure that no other language has this feature....maybe C. |
![]() |
| Thread Tools | |
| Display Modes | |
|
|