Re: Re[4]: Need a more elegant way of bitwise ORing values

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, 2007-06-13 at 15:05 +0100, Richard Davey wrote:
> Hi Tijnema,
> 
> Wednesday, June 13, 2007, 2:42:28 PM, you wrote:
> 
> > Nice one, but you could also do it like this:
> 
> > <?php
> > $filter['flags'] = FALSE;
> 
> > if ($allow_fraction)
> > {
> >    $filter['flags'] = $filter['flags'] | FILTER_FLAG_ALLOW_FRACTION;
> > }
> 
> > if ($allow_thousand)
> > {
> >    $filter['flags'] = $filter['flags'] | FILTER_FLAG_ALLOW_THOUSAND;
> > }
> 
> > if ($allow_scientific)
> > {
> >    $filter['flags'] = $filter['flags'] | FILTER_FLAG_ALLOW_SCIENTIFIC;
> > }
> 
> ?>>
> 
> > Little bit simpler huh?
> 
> Yup.. even nicer, I'm using that method now :)

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;
}

?>

Cheers,
Rob.
-- 
.------------------------------------------------------------.
| InterJinn Application Framework - http://www.interjinn.com |
:------------------------------------------------------------:
| An application and templating framework for PHP. Boasting  |
| a powerful, scalable system for accessing system services  |
| such as forms, properties, sessions, and caches. InterJinn |
| also provides an extremely flexible architecture for       |
| creating re-usable components quickly and easily.          |
`------------------------------------------------------------'

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux