bit manipulation - PHP - converting bitmask -


say assign following fruits:

array ('1' => 'apple', '2' => 'banana', '4' => 'grape', '8' => 'orange')

if wanted represent apple , banana, following: 0001 or 0010 0011 (or 3), right?

given number 3, how convert 1 , 2?

all keys loaded $keys:

$keys = array(); $value = 3;  foreach ($arr $key => $val) {    if ($value & $key)    {       $keys[] = $key;    } } 

Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -