Re[6]: [PHP] Need a more elegant way of bitwise ORing values
| From: | tedd | Date: | Sat, 16 Jun 2007 12:18:58 +0000 |
| Subject: | Re[6]: [PHP] Need a more elegant way of bitwise ORing values | ||
| References: | 1 2 3 4 5 6 7 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-257165@lists.php.net to get a copy of this message | ||
At 3:19 PM +0100 6/13/07, Richard Davey wrote:
if( $allow_thousand )<?php$filter['flags'] = 0;if( $allow_fraction ){$filter['flags'] |= FILTER_FLAG_ALLOW_FRACTION;}
{
$filter['flags'] |= FILTER_FLAG_ALLOW_THOUSAND;} if( $allow_scientific )
{
$filter['flags'] |= FILTER_FLAG_ALLOW_SCIENTIFIC;} ?>> I don't think it's *terribly* verbose, as it has good sentence structure to it, but your version is certainly more efficient, hence I've swapped to that. Any other takers? ;) Rich: How about? switch (1) { case $allow_fraction: $filter['flags'] = FILTER_FLAG_ALLOW_FRACTION; break; case $allow_thousand: $filter['flags'] = FILTER_FLAG_ALLOW_THOUSAND; break; case $allow_scientific: $filter['flags'] = FILTER_FLAG_ALLOW_SCIENTIFIC; break; } Would that not work? Cheers, tedd -- ------- http://sperling.com http://ancientstones.com http://earthstones.com