如何使用PHP将base10数字转换为数组

The meaning is : How to store in a single database field, multiple value as, for example, Optin data.

In order to do that, i've to know how to code and decode the value. I've an array with different optin values:

$optin = array (
    '1' => 'SMS',
    '2' => 'Email',
    '4' => 'Mail',
    '8' => 'AppsPushNotif',
    '16' => 'Partners',
    '32' => 'Gaming Partners'
);

ie.: I'll store,in optin field : - '7' if the user is opt-in for SMS,Email and Mail (4+2+1) or - '40' for AppsPushNotif and Gaming_Partners

I would like found a way to decode 7 or 40 values into an array with optin's arrays values.

Many thanks

PS: Thanks to Cyclone for the solution :

$output = '';
$value = 40;
$keys = array_keys($food);  

foreach($keys as $key) {   
    if($value & $key) $output .= $food[$key].',';  
}  

print rtrim($output, ',');

A solution in one line to unpack $value into individual values that appear as keys in $optin:

$value = 40;

$keys = array_map(
    function($i) { return 1 << $i; },
    array_keys(array_filter(str_split(strrev(decbin($value)))))
);

print_r($keys);

The output is:

Array
(
    [0] => 8
    [1] => 32
)

This should work:

$output = ''; 
$value = 40; 
$keys = array_keys($food); 

foreach($keys as $key) { 
  if($value & $key) 
    $output .= $food[$key].','; 
} 
print rtrim($output, ',');