How to get values of selected options in Form api? I am using Form api to build one form.In that I have used select type field and for that options are coming from an array. Below is the code

  $fnames = array();
  $dir_path = variable_get('file_public_path', conf_path(). '/files');
  $files1 = scandir($dir_path); 
  $dirs = glob($dir_path . '/*' , GLOB_ONLYDIR);
    foreach($dirs as $directs){
     $names = explode('/', $directs);//
     $fnames[] = end($names);
    }

  $form['select_list'] = array(
    '#type' =&gt; 'select',
    '#title' =&gt; t('Folder Names'),
    '#options' =&gt; $fnames,
  );


While displaying on the select list it will display all names but when I will fetch the value in one of the submit function it will show only index value not the name.

function custom_submit_file_upload($form, &amp;$form_state){
  $foldername = $form_state['values']['select_list'];
}


Here it shows, 

$foldername = 0 or 1 or 2 whatever I select in the options, 


but I need name of the selected element not the index values.
Please suggest me to get the names.Thank you in advance..
Since the form submission handler has access to the $form variable, you just use the following code.

$foldername = $form['select_list']['#options'][$form_state['values']['select_list']];


To make it clear with an example: $form['select_list']['#options'] is an array like array( 1 =&gt; 'first folder', 2 =&gt; 'second folder'), and $form_state['values']['select_list'] is a value between 1 and 2.