<ole>
Du kan også bruge bit shifting:
http://dk2.php.net/manual/en/language.operators.bitwise.phpPrøv denne kode:
<?php
/*
Her kan du se, hvad der sker,
når man bit shifter et 1-tal
med forskellige værdier
*/
print "(1<<0) => ".(1<<0)."<br>";
print "(1<<1) => ".(1<<1)."<br>";
print "(1<<2) => ".(1<<2)."<br>";
print "(1<<3) => ".(1<<3)."<br>";
print "(1<<4) => ".(1<<4)."<br>";
print "(1<<5) => ".(1<<5)."<br>";
print "(1<<6) => ".(1<<6)."<br>";
print "(1<<7) => ".(1<<7)."<br>";
print "(1<<8) => ".(1<<8)."<br>";
print "(1<<9) => ".(1<<9)."<br>";
print "(1<<10) => ".(1<<10)."<hr>";
?>
<?php
/*
Her gemmer vi tre forskellige værdier
i et enkelt tal - og finder bagefter ud af
hvilke værdier, der er gemt i variablen
*/
// Opret en variabel med værdien 1
$foo = 1;
// Sæt 3, 5 og 8 på variablen
$foo += (1<<3);
$foo += (1<<5);
$foo += (1<<8);
print "Her har vi sat 3, 5 og 8 på variablen, som nu indeholder tallet:<br>";
print "8 + 32 + 256 = ".$foo."<hr>";
// Tjek, hvad der er sat
if ( $foo&(1<<1) ) print "1 er sat <br>";
if ( $foo&(1<<2) ) print "2 er sat <br>";
if ( $foo&(1<<3) ) print "3 er sat <br>";
if ( $foo&(1<<4) ) print "4 er sat <br>";
if ( $foo&(1<<5) ) print "5 er sat <br>";
if ( $foo&(1<<6) ) print "6 er sat <br>";
if ( $foo&(1<<7) ) print "7 er sat <br>";
if ( $foo&(1<<8) ) print "8 er sat <br>";
if ( $foo&(1<<9) ) print "9 er sat <br>";
if ( $foo&(1<<10) ) print "10 er sat <br>";
if ( $foo&(1<<11) ) print "11 er sat <br>";
if ( $foo&(1<<12) ) print "12 er sat <br>";
?>
/mvh
</bole>