________________________________

> From: Richard Davey [mailto:[EMAIL PROTECTED]
> Sent: Wed 13/06/2007 15:19
> To: PHP List
> 
> > Hi Robert,
> 
> Wednesday, June 13, 2007, 3:15:39 PM, you wrote:
> 
> > It's terribly verbose and inefficient...
> 
> > <?php
> 
> > $filter['flags'] = 0;
> 
> > if( $allow_fraction )
> > {
> >     $filter['flags'] |= FILTER_FLAG_ALLOW_FRACTION;
> > }
> 
> > if( $allow_thousand )
> > {
> >     $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? ;)

Well, I don't know about more efficient but I'd be terribly tempted to express 
it like this:

  $filter['flags'] = $allow_fraction   ? FILTER_FLAG_ALLOW_FRACTION : 0
                   | $allow_thousand   ? FILTER_FLAG_ALLOW_THOUSAND : 0
                   | $allow_scientific ? FILTER_FLAG_ALLOW_SCIENTIFIC : 0;

Whether you think this is more readable and/or less verbose probably depends on 
personal taste! ;)
 
--------------------------------------------------------------------- 
Mike Ford,  Electronic Information Services Adviser, 
Learning Support Services, Learning & Information Services, 
JG125, James Graham Building, Leeds Metropolitan University, 
Headingley Campus, LEEDS,  LS6 3QS,  United Kingdom 
Email: [EMAIL PROTECTED] 
Tel: +44 113 812 4730          Fax:  +44 113 812 3211 



To view the terms under which this email is distributed, please go to 
http://disclaimer.leedsmet.ac.uk/email.htm

Reply via email to