Using variable_set with associative array I use checkboxes in a form to capture a users selection as:

$form['mbo_block_config']['livembo_classes_details'] = array(
                '#type' =&gt; 'checkboxes',
                '#title' =&gt; t('Class Details'),
                '#description' =&gt; t('Choose class details to display.'),
                '#options' =&gt; $details,
                '#default_value' =&gt; variable_get('livembo_classes_details', array('c_id','c_cd_name')),
                '#required' =&gt; TRUE,                
                );


The available options are stored in $details which is an associative array:

$details = array(
          'c_id' =&gt; t('Class ID'),
          'c_cd_name' =&gt; t('Class Name'),
          'c_cd_description' =&gt; t('Class Description'),
          'c_l_name' =&gt; t('Location: Name'),
          'c_l_city' =&gt; t('Location: City'),
          'c_l_full' =&gt; t('Location: Full Address'),
          'c_l_phone' =&gt; t('Location: Contact Number'),
          'c_s_FullName' =&gt; t('Staff: Name'),     
          'c_start ' =&gt; t('Class Start Time'),
          'c_end' =&gt; t('Class End Time')
          );


I use variable set variable_set('livembo_classes_details', $edit['livembo_classes_details']); which works fine, however it flattens the array and changes the keys to values as per:

Array ( [0] =&gt; c_id [1] =&gt; c_l_phone [2] =&gt; c_l_name )


How can I retain the key/value format in the array as originally specified? For example:

Array ( [c_id] =&gt; t('Class ID') [c_l_phone] =&gt; t('Location: Contact Number') [c_l_name] =&gt; t('Location: Name') )
The problem is not variable_get()/set(). It stores whatever you pass to it as a serialized array.

However, what you are saving are the keys of your array, because that's what is passed from the browser when submitting the form. This is also what is expected in the #default_value so it needs to be like this.

When accessing the information, all you need to do is get the intersection of your $details and the selected keys like this:

$selected_details = array_intersect_key($details, array_flip(variable_get('livembo_classes_details', array('c_id','c_cd_name')));


I would recommend to add a helper function which returns $details if you haven't already, so you can re-use that definition and a second helper function which contains the above code.