Daevid Vincent wrote:
TR class=?php echo ($r = !$r) ? dataRow1 : dataRow2; ?
I love the simplicity, and very cool.
But why does the ($r=!$r) ternary condition work?. (I understand
that it DOES but not WHY.)
TIA,
Jeff
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit:
On Fri, 2007-10-05 at 14:00 -0500, Jeff Cohan wrote:
Daevid Vincent wrote:
TR class=?php echo ($r = !$r) ? dataRow1 : dataRow2; ?
I love the simplicity, and very cool.
But why does the ($r=!$r) ternary condition work?. (I understand
that it DOES but not WHY.)
Because he's rotating
[snip]
But why does the ($r=!$r) ternary condition work?. (I understand
that it DOES but not WHY.)
Because he's rotating between boolean values.
$r = true;
$r = !$r;// Now $r is false;
$r = !$r;// Now $r is true;
$r = !$r;// Now $r is false;
$r = !$r;//
Jay Blanchard wrote:
We just did that proof in the office as well. With a little echoing you
will see that when $r is TRUE it is set to 1, when it is false it is set
to NULL.
But it still should not work logically because you are performing an
assignment in the IF (it doesn't have to be ternary
[snip]
But why does the ($r=!$r) ternary condition work?. (I understand
that it DOES but not WHY.)
[/snip]
Check this out -
http://us3.php.net/manual/en/language.operators.assignment.php
It says the value of the assignment is the value assigned, so maybe
assignments to anything other than 0
On Fri, 2007-10-05 at 13:46 -0500, Jay Blanchard wrote:
[snip]
But why does the ($r=!$r) ternary condition work?. (I understand
that it DOES but not WHY.)
[/snip]
Check this out -
http://us3.php.net/manual/en/language.operators.assignment.php
It says the value of the assignment is
[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
--
On Fri, 2007-10-05 at 14:49 -0400, Nathan Nobbe wrote:
On 10/5/07, Jay Blanchard [EMAIL PROTECTED] wrote:
It looks like PHP has an unintentional feature. Doing this;
if($r =
!$r) should always return TRUE because it is an assignment. I
don't know
[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]
On Fri, 2007-10-05 at 14:04 -0500, Jay Blanchard wrote:
[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]
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?
[snip]
if($r = !$r)
it is a conditional test.
? foo : bar;
...is the ternary operation. Just wanted to clean up the usage there.
Did I miss something? The code I saw was the following:
TR class=?php echo ($r = !$r) ? dataRow1 : dataRow2; ?
And that is definitely using the
PROTECTED]
Sent: Friday, October 05, 2007 11:39 AM
To: Robert Cummings; Jeff Cohan
Cc: php-general@lists.php.net
Subject: RE: [PHP] Alternate Colors in Rows ($r=!$r)
[snip]
But why does the ($r=!$r) ternary condition work?. (I understand
that it DOES but not WHY.)
Because he's
Nathan Nobbe wrote:
personally, i wont argue w/ the compact nature of the
statement; its nice.
I agree. Very elegant. Thanks for the clarifications, folks.
its mysterious statements like this that make code fragile,
imho. i prefer the modulus approach.
I would have agreed before reading
On Fri, 2007-10-05 at 14:17 -0500, Jay Blanchard wrote:
[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
On 10/5/07, Jay Blanchard [EMAIL PROTECTED] wrote:
It looks like PHP has an unintentional feature. Doing this; if($r =
!$r) should always return TRUE because it is an assignment. I don't know
if I would rely on this.
its not an unintentional operation; its the order of operations.
logical
16 matches
Mail list logo