How to pass an array to drupal7 form select as value of #options? This problem makes my head burn all day. Please see the code below.
I got a variable $region_value contains the region value with the same structure listed in the code. However different page has a different region value, so I have to use a variable to store it, it's not static.

$region_value = array(0 =&gt; 'US', 1 =&gt; 'EU')
//form code details have been left out.
//the below code define the form.
$form['region_options'] = array(
                '#type' =&gt; 'select',
                'prefix' =&gt; 'Region',
                '#options' =&gt; $region_value,
                               );


now I get the problem, cuz drupal can't accept the value of $region_value, something wrong happened cuz the $region_value's can not be passed into the form function itself in template files, it might be caused by the drupal core settings. I know it's not a good choice to write functions or other customer variables in the template files, but it's convenient for simple test, you don't have to dump the cash.

So my problem is, is there a mean to pass a variable value into the form function?

//variable set here
$options = array('foo' =&gt; 'bar',...)
//form define function goes here
function region_form($form, &amp;$form_state) {
            $form['submit'] = array(
                                   '#type' =&gt; 'select',
                                   '#options' =&gt; $options,
                                   );
            return $form;
          }


Much appreciated for all advises.
Have a look at the Form API docs for select lists. #options is the correct property to set the options, and #default_value is used to set a default value. 

Using #value means the user input will be ignored, and whatever you've set as #value will wind up being the submitted value. Since you're declaring a non-multiple select list, that value needs to be an integer (not an array) anyway.

Try something like this:

$region_value = array(0 =&gt; 'US', 1 =&gt; 'EU');
$form['region_options'] = array(
  '#type' =&gt; 'select',
  '#prefix' =&gt; 'Region',
  '#options' =&gt; $region_value,
  '#default_value' =&gt; 0, // e.g. Set US as default selected value (appropriate array key from $region_value)
);