Variable saved as string, not as integer I have a problem when updating a variable with return system_settings_form($form) - Basically, I store a variable as an integer, but when I press Save configuration, it works very well except that it saves the variable as a string, not an integer.

Here's my function:

function my_module_settings() {
  $form['my_variable'] = array(
    '#type' =&gt; 'select',
    '#title' =&gt; t('My module variable'),
    '#description' =&gt; t('Update my module variable.'),
    '#options' =&gt; array(
       1 =&gt; t('Set it to 1'),
       2 =&gt; t('Set it to 2'),
       3 =&gt; t('Set it to 3'),
    ),
    '#default_value' =&gt; variable_get('my_variable', 3)
  );
  return system_settings_form($form);
}


So, if I select "Set it to 2" in the select list and hit save, I'll be getting number 2 surrounded by quotes ("2"). I've confirmed with PHP gettype that there's indeed a change of data type.

I wonder if it's related to the select list or something foolish I'm doing? I've tried using a checkbox instead and data type is correctly updated as an integer.

I've been scratching my head without finding a correct solution. Any idea what's going on?
It probably has to do with how php handles POST values.

That is just generating a form element, which when the form is saved will get sent to the server as a string. Here's an attempt at phpfiddle to show you what's going on: http://phpfiddle.org/main/code/dmk-npy.

Basically you're either going to have to intercept the form submit and cast the variable to (int) there, or you'll need to cast it to an int when you're pulling the variable out.

Edit: Though I have no idea why your checkbox would be saving it as an integer.