original_string: public static function select(array $options, $name, $selected = '', $nothing = array('' => 'choosedots'), array $attributes = null) {
          $attributes = (array)$attributes;
          if (is_array($nothing)) {
              foreach ($nothing as $k=>$v) {
                  if ($v === 'choose' or $v === 'choosedots') {
                      $nothing[$k] = get_string('choosedots');
                  }
              }
              $options = $nothing + $options; // keep keys, do not override
  
          } else if (is_string($nothing) and $nothing !== '') {
              // BC
              $options = array(''=>$nothing) + $options;
          }
  
          // we may accept more values if multiple attribute specified
          $selected = (array)$selected;
          foreach ($selected as $k=>$v) {
              $selected[$k] = (string)$v;
          }
  
          if (!isset($attributes['id'])) {
              $id = 'menu'.$name;
              // name may contaion [], which would make an invalid id. e.g. numeric question type editing form, assignment quickgrading
              $id = str_replace('[', '', $id);
              $id = str_replace(']', '', $id);
              $attributes['id'] = $id;
          }
  
          if (!isset($attributes['class'])) {
              $class = 'menu'.$name;
              // name may contaion [], which would make an invalid class. e.g. numeric question type editing form, assignment quickgrading
              $class = str_replace('[', '', $class);
              $class = str_replace(']', '', $class);
              $attributes['class'] = $class;
          }
          $attributes['class'] = 'select custom-select ' . $attributes['class']; // Add 'select' selector always.
  
          $attributes['name'] = $name;
  
          if (!empty($attributes['disabled'])) {
              $attributes['disabled'] = 'disabled';
          } else {
              unset($attributes['disabled']);
          }
  
          $output = '';
          foreach ($options as $value=>$label) {
              if (is_array($label)) {
                  // ignore key, it just has to be unique
                  $output .= self::select_optgroup(key($label), current($label), $selected);
              } else {
                  $output .= self::select_option($label, $value, $selected);
              }
          }
          return self::tag('select', $output, $attributes);
      }
code: public static function select(array $options, $name, $selected = '', $nothing = array('' => 'choosedots'), array $attributes = null) {
          $attributes = (array)$attributes;
          if (is_array($nothing)) {
              foreach ($nothing as $k=>$v) {
                  if ($v === 'choose' or $v === 'choosedots') {
                      $nothing[$k] = get_string('choosedots');
                  }
              }
              $options = $nothing + $options; // keep keys, do not override
  
          } else if (is_string($nothing) and $nothing !== '') {
              // BC
              $options = array(''=>$nothing) + $options;
          }
  
          // we may accept more values if multiple attribute specified
          $selected = (array)$selected;
          foreach ($selected as $k=>$v) {
              $selected[$k] = (string)$v;
          }
  
          if (!isset($attributes['id'])) {
              $id = 'menu'.$name;
              // name may contaion [], which would make an invalid id. e.g. numeric question type editing form, assignment quickgrading
              $id = str_replace('[', '', $id);
              $id = str_replace(']', '', $id);
              $attributes['id'] = $id;
          }
  
          if (!isset($attributes['class'])) {
              $class = 'menu'.$name;
              // name may contaion [], which would make an invalid class. e.g. numeric question type editing form, assignment quickgrading
              $class = str_replace('[', '', $class);
              $class = str_replace(']', '', $class);
              $attributes['class'] = $class;
          }
          $attributes['class'] = 'select custom-select ' . $attributes['class']; // Add 'select' selector always.
  
          $attributes['name'] = $name;
  
          if (!empty($attributes['disabled'])) {
              $attributes['disabled'] = 'disabled';
          } else {
              unset($attributes['disabled']);
          }
  
          $output = '';
          foreach ($options as $value=>$label) {
              if (is_array($label)) {
                  // ignore key, it just has to be unique
                  $output .= self::select_optgroup(key($label), current($label), $selected);
              } else {
                  $output .= self::select_option($label, $value, $selected);
              }
          }
          return self::tag('select', $output, $attributes);
      }
code_tokens: public static function select ( array $ options , $ name , $ selected = '' , $ nothing = array ( '' => 'choosedots' ) , array $ attributes = null ) { $ attributes = ( array ) $ attributes ; if ( is_array ( $ nothing ) ) { foreach ( $ nothing as $ k => $ v ) { if ( $ v === 'choose' or $ v === 'choosedots' ) { $ nothing [ $ k ] = get_string ( 'choosedots' ) ; } } $ options = $ nothing + $ options ; // keep keys, do not override } else if ( is_string ( $ nothing ) and $ nothing !== '' ) { // BC $ options = array ( '' => $ nothing ) + $ options ; } // we may accept more values if multiple attribute specified $ selected = ( array ) $ selected ; foreach ( $ selected as $ k => $ v ) { $ selected [ $ k ] = ( string ) $ v ; } if ( ! isset ( $ attributes [ 'id' ] ) ) { $ id = 'menu' . $ name ; // name may contaion [], which would make an invalid id. e.g. numeric question type editing form, assignment quickgrading $ id = str_replace ( '[' , '' , $ id ) ; $ id = str_replace ( ']' , '' , $ id ) ; $ attributes [ 'id' ] = $ id ; } if ( ! isset ( $ attributes [ 'class' ] ) ) { $ class = 'menu' . $ name ; // name may contaion [], which would make an invalid class. e.g. numeric question type editing form, assignment quickgrading $ class = str_replace ( '[' , '' , $ class ) ; $ class = str_replace ( ']' , '' , $ class ) ; $ attributes [ 'class' ] = $ class ; } $ attributes [ 'class' ] = 'select custom-select ' . $ attributes [ 'class' ] ; // Add 'select' selector always. $ attributes [ 'name' ] = $ name ; if ( ! empty ( $ attributes [ 'disabled' ] ) ) { $ attributes [ 'disabled' ] = 'disabled' ; } else { unset ( $ attributes [ 'disabled' ] ) ; } $ output = '' ; foreach ( $ options as $ value => $ label ) { if ( is_array ( $ label ) ) { // ignore key, it just has to be unique $ output .= self :: select_optgroup ( key ( $ label ) , current ( $ label ) , $ selected ) ; } else { $ output .= self :: select_option ( $ label , $ value , $ selected ) ; } } return self :: tag ( 'select' , $ output , $ attributes ) ; }
docstring: Generates a simple select form field
  
  @param array $options associative array value=>label ex.:
  array(1=>'One, 2=>Two)
  it is also possible to specify optgroup as complex label array ex.:
  array(array('Odd'=>array(1=>'One', 3=>'Three)), array('Even'=>array(2=>'Two')))
  array(1=>'One', '--1uniquekey'=>array('More'=>array(2=>'Two', 3=>'Three')))
  @param string $name name of select element
  @param string|array $selected value or array of values depending on multiple attribute
  @param array|bool $nothing add nothing selected option, or false of not added
  @param array $attributes html select element attributes
  @return string HTML fragment
docstring_tokens: Generates a simple select form field