RE: [PHP] Re: how to say "inverse your value" (to a boolean)?
| From: | Ford, Mike | Date: | Tue, 11 Aug 2009 09:56:34 +0000 |
| Subject: | RE: [PHP] Re: how to say "inverse your value" (to a boolean)? | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-296614@lists.php.net to get a copy of this message | ||
> -----Original Message-----
> From: Ralph Deffke [mailto:ralph_deffke@yahoo.de]
> Sent: 11 August 2009 01:45
>
> ummmm...
> try
> echo "<pre>";
> 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.ford@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