Set Custom value in checkbox I have an array...

    $my_array = array(1 =&gt; 'Value One', 2 =&gt; 'Value Two',3 =&gt; 'Value Three');


In Form API, I want to create checkbox for each value.

    foreach($my_array as $key =&gt; $value) {
      $form['custom_field'] = array(
        '#type' =&gt; 'checkbox',
        '#title' =&gt; $value,
        '#default_value' =&gt; variable_get('custom_field'),
      );
    }


by default is stores in value, '0' or '1'.
It should actuly be saving the $key as value.

I know this can be done simply using 'type' as 'checkboxes' but actuly I need to goroup it each time each check box with a text field.

    foreach($my_array as $key =&gt; $value) {
      $form['custom_field'.$key] = array(
          '#type' =&gt; 'checkbox',
          '#title' =&gt; $value,
          '#default_value' =&gt; variable_get('custom_field'),
        );
        $form['custom_field'.$key] = array(
          '#type' =&gt; 'textfield',
          '#title' =&gt; 'Limit',
          '#size' =&gt; 10,
          '#maxlength' =&gt; 10,
          '#default_value' =&gt; variable_get('limit_variable'),
          '#required' =&gt; TRUE,
        );
      }


`
Any help?
You can try adding '#return_value':

foreach($my_array as $key =&gt; $value) {
      $form['custom_field'] = array(
        '#type' =&gt; 'checkbox',
        '#return_value' =&gt; $key,
        '#title' =&gt; $value,
        '#default_value' =&gt; variable_get('custom_field'),
      );
    }