How's your Mum? tedd wrote:
Hey: Didn't anyone like my -- "Whenever I need a 1 or 0, I use ($i & 1)." -- comment? I though that was pretty clever, but no one even said "How's your Mum?".
well it's a basic bitwise operation, anyone who has been doing for a while wouldn't think much of it and people who are not yet aware of bitwise operations will probably gloss over it. that said how often do you _really_ need a 1 or a 0, let's assume that your code has an $i and the code can be certain it's an integer then converting it to 1 or 0 is not that different to casting to a boolean, I'm assuming that the 1 or 0 are used to detemine an on/off state. is my assumption correct? if so then take another good look at the way php autocasts variables, for instance tyr running this: $zero = 0; $one = 1; var_dump( (false == $zero), (true == $one), ((bool)$zero), ($zero & 1), ((bool)($zero & 1)), ((bool)$one), ($one & 1), ((bool)($one & 1)) );
tedd
-- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php