At 10:18 06.11.2002, Daevid Vincent said: --------------------[snip]-------------------- >doesn't lend itself nicely to expansion, but may be my only way. I just >have a gut feeling that it can be automated somehow. To turn 1,3,4 into >10110 seems like there is some 'math' there that can work. I also --------------------[snip]--------------------
It's quite easy using the left-shift operator "<<". Note that the function below only works for values 1-31 on 32bit systems. <?php function makebits(&$array) { $result = 0; foreach ($array as $seq) { if (is_numeric($seq)) { $i = 1 << ($seq-1); // assuming ID's are 1-based $result += $i; } } return $result; } $a = array(1,3,5,9); // 1 0001 0101 = 0x115 echo '<xmp>', sprintf('0x%x', makebits($a)), "\n</xmp>"; ?> -- >O Ernest E. Vogelsinger (\) ICQ #13394035 ^ http://www.vogelsinger.at/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php