RE: [PHP] Re: how to say "inverse your value" (to a boolean)?
> -Original Message- > From: Ralph Deffke [mailto:ralph_def...@yahoo.de] > Sent: 11 August 2009 01:45 > > u... > try > echo ""; > for( $i=0 ; $i<10; $i++){ > echo "something " . (($a = $a^1) ? "red\n" : "green\n"); > } The ^ operator is one that has an assigning version, so the above can be slightly shortened to: echo "something " . (($a ^= 1) ? "red\n" : "green\n"); Cheers! Mike -- Mike Ford, Electronic Information Developer, Libraries and Learning Innovation, Leeds Metropolitan University, C507, Civic Quarter Campus, Woodhouse Lane, LEEDS, LS1 3HE, United Kingdom Email: m.f...@leedsmet.ac.uk Tel: +44 113 812 4730 To view the terms under which this email is distributed, please go to http://disclaimer.leedsmet.ac.uk/email.htm -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: how to say "inverse your value" (to a boolean)?
No...not zerowing...no... But yes, the ternary operator is the bomb, which you can get carried away with. Daevid knows what I mean :) Adam. On Mon, Aug 10, 2009 at 6:59 PM, Daevid Vincent wrote: > Pretty much the best operator ever invented IMHO. And Since PHP 5.3, it is > possible to leave out the middle part of the ternary operator. Expression > expr1 ?: expr3 returns expr1 if expr1 evaluates to TRUE, and expr3 > otherwise. Awesome! > > Also, Adam Randall set up us the bomb. ;-) > (http://www.youtube.com/watch?v=qItugh-fFgg) > >> -Original Message- >> From: Adam Randall [mailto:randa...@gmail.com] >> Sent: Monday, August 10, 2009 6:41 PM >> To: php-general@lists.php.net >> Subject: Re: [PHP] Re: how to say "inverse your value" (to a boolean)? >> >> http://us3.php.net/manual/en/language.operators.comparison.php >> >> Find "Ternary" on that page. >> >> It's a shortened conditional: >> >> cond ? true : false >> >> Adam. >> >> On Mon, Aug 10, 2009 at 6:27 PM, John >> Butler wrote: >> >> echo "something " . (($a = $a^1) ? "red\n" : "green\n"); >> > >> > Re: The "?" char in this line above.. >> > where in the php docs can I read about what that is doing? >> > I have not come across this construct before today, from you guys. >> > >> > thanks >> > -John >> > >> > -- >> > PHP General Mailing List (http://www.php.net/) >> > To unsubscribe, visit: http://www.php.net/unsub.php >> > >> > >> >> >> >> -- >> Adam Randall >> http://www.xaren.net >> AIM: blitz574 >> >> -- >> PHP General Mailing List (http://www.php.net/) >> To unsubscribe, visit: http://www.php.net/unsub.php >> > > -- Adam Randall http://www.xaren.net AIM: blitz574 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Re: how to say "inverse your value" (to a boolean)?
Pretty much the best operator ever invented IMHO. And Since PHP 5.3, it is possible to leave out the middle part of the ternary operator. Expression expr1 ?: expr3 returns expr1 if expr1 evaluates to TRUE, and expr3 otherwise. Awesome! Also, Adam Randall set up us the bomb. ;-) (http://www.youtube.com/watch?v=qItugh-fFgg) > -Original Message- > From: Adam Randall [mailto:randa...@gmail.com] > Sent: Monday, August 10, 2009 6:41 PM > To: php-general@lists.php.net > Subject: Re: [PHP] Re: how to say "inverse your value" (to a boolean)? > > http://us3.php.net/manual/en/language.operators.comparison.php > > Find "Ternary" on that page. > > It's a shortened conditional: > > cond ? true : false > > Adam. > > On Mon, Aug 10, 2009 at 6:27 PM, John > Butler wrote: > >> echo "something " . (($a = $a^1) ? "red\n" : "green\n"); > > > > Re: The "?" char in this line above.. > > where in the php docs can I read about what that is doing? > > I have not come across this construct before today, from you guys. > > > > thanks > > -John > > > > -- > > PHP General Mailing List (http://www.php.net/) > > To unsubscribe, visit: http://www.php.net/unsub.php > > > > > > > > -- > Adam Randall > http://www.xaren.net > AIM: blitz574 > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: how to say "inverse your value" (to a boolean)?
http://us3.php.net/manual/en/language.operators.comparison.php Find "Ternary" on that page. It's a shortened conditional: cond ? true : false Adam. On Mon, Aug 10, 2009 at 6:27 PM, John Butler wrote: >> echo "something " . (($a = $a^1) ? "red\n" : "green\n"); > > Re: The "?" char in this line above.. > where in the php docs can I read about what that is doing? > I have not come across this construct before today, from you guys. > > thanks > -John > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > > -- Adam Randall http://www.xaren.net AIM: blitz574 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: how to say "inverse your value" (to a boolean)?
echo "something " . (($a = $a^1) ? "red\n" : "green\n"); Re: The "?" char in this line above.. where in the php docs can I read about what that is doing? I have not come across this construct before today, from you guys. thanks -John -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: how to say "inverse your value" (to a boolean)?
= ! ! =) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php