original_string: protected function validate_format_options(array $rawdata, int $sectionid = null) : array {
          if (!$sectionid) {
              $allformatoptions = $this->course_format_options(true);
          } else {
              $allformatoptions = $this->section_format_options(true);
          }
          $data = array_intersect_key($rawdata, $allformatoptions);
          foreach ($data as $key => $value) {
              $option = $allformatoptions[$key] + ['type' => PARAM_RAW, 'element_type' => null, 'element_attributes' => [[]]];
              $data[$key] = clean_param($value, $option['type']);
              if ($option['element_type'] === 'select' && !array_key_exists($data[$key], $option['element_attributes'][0])) {
                  // Value invalid for select element, skip.
                  unset($data[$key]);
              }
          }
          return $data;
      }
code: protected function validate_format_options(array $rawdata, int $sectionid = null) : array {
          if (!$sectionid) {
              $allformatoptions = $this->course_format_options(true);
          } else {
              $allformatoptions = $this->section_format_options(true);
          }
          $data = array_intersect_key($rawdata, $allformatoptions);
          foreach ($data as $key => $value) {
              $option = $allformatoptions[$key] + ['type' => PARAM_RAW, 'element_type' => null, 'element_attributes' => [[]]];
              $data[$key] = clean_param($value, $option['type']);
              if ($option['element_type'] === 'select' && !array_key_exists($data[$key], $option['element_attributes'][0])) {
                  // Value invalid for select element, skip.
                  unset($data[$key]);
              }
          }
          return $data;
      }
code_tokens: protected function validate_format_options ( array $ rawdata , int $ sectionid = null ) : array { if ( ! $ sectionid ) { $ allformatoptions = $ this -> course_format_options ( true ) ; } else { $ allformatoptions = $ this -> section_format_options ( true ) ; } $ data = array_intersect_key ( $ rawdata , $ allformatoptions ) ; foreach ( $ data as $ key => $ value ) { $ option = $ allformatoptions [ $ key ] + [ 'type' => PARAM_RAW , 'element_type' => null , 'element_attributes' => [ [ ] ] ] ; $ data [ $ key ] = clean_param ( $ value , $ option [ 'type' ] ) ; if ( $ option [ 'element_type' ] === 'select' && ! array_key_exists ( $ data [ $ key ] , $ option [ 'element_attributes' ] [ 0 ] ) ) { // Value invalid for select element, skip. unset ( $ data [ $ key ] ) ; } } return $ data ; }
docstring: Prepares values of course or section format options before storing them in DB
  
  If an option has invalid value it is not returned
  
  @param array $rawdata associative array of the proposed course/section format options
  @param int|null $sectionid null if it is course format option
  @return array array of options that have valid values
docstring_tokens: Prepares values of course or section format options before storing them in DB