original_string: protected function flatten_options($options, $nothing) {
          $flattened = [];
  
          foreach ($options as $value => $option) {
              if (is_array($option)) {
                  foreach ($option as $groupname => $optoptions) {
                      if (!isset($flattened[$groupname])) {
                          $flattened[$groupname] = [
                              'name' => $groupname,
                              'isgroup' => true,
                              'options' => []
                          ];
                      }
                      foreach ($optoptions as $optvalue => $optoption) {
                          $cleanedvalue = $this->clean_url($optvalue);
                          $flattened[$groupname]['options'][$cleanedvalue] = [
                              'name' => $optoption,
                              'value' => $cleanedvalue,
                              'selected' => $this->selected == $optvalue,
                          ];
                      }
                  }
  
              } else {
                  $cleanedvalue = $this->clean_url($value);
                  $flattened[$cleanedvalue] = [
                      'name' => $option,
                      'value' => $cleanedvalue,
                      'selected' => $this->selected == $value,
                  ];
              }
          }
  
          if (!empty($nothing)) {
              $value = key($nothing);
              $name = reset($nothing);
              $flattened = [
                  $value => ['name' => $name, 'value' => $value, 'selected' => $this->selected == $value]
              ] + $flattened;
          }
  
          // Make non-associative array.
          foreach ($flattened as $key => $value) {
              if (!empty($value['options'])) {
                  $flattened[$key]['options'] = array_values($value['options']);
              }
          }
          $flattened = array_values($flattened);
  
          return $flattened;
      }
code: protected function flatten_options($options, $nothing) {
          $flattened = [];
  
          foreach ($options as $value => $option) {
              if (is_array($option)) {
                  foreach ($option as $groupname => $optoptions) {
                      if (!isset($flattened[$groupname])) {
                          $flattened[$groupname] = [
                              'name' => $groupname,
                              'isgroup' => true,
                              'options' => []
                          ];
                      }
                      foreach ($optoptions as $optvalue => $optoption) {
                          $cleanedvalue = $this->clean_url($optvalue);
                          $flattened[$groupname]['options'][$cleanedvalue] = [
                              'name' => $optoption,
                              'value' => $cleanedvalue,
                              'selected' => $this->selected == $optvalue,
                          ];
                      }
                  }
  
              } else {
                  $cleanedvalue = $this->clean_url($value);
                  $flattened[$cleanedvalue] = [
                      'name' => $option,
                      'value' => $cleanedvalue,
                      'selected' => $this->selected == $value,
                  ];
              }
          }
  
          if (!empty($nothing)) {
              $value = key($nothing);
              $name = reset($nothing);
              $flattened = [
                  $value => ['name' => $name, 'value' => $value, 'selected' => $this->selected == $value]
              ] + $flattened;
          }
  
          // Make non-associative array.
          foreach ($flattened as $key => $value) {
              if (!empty($value['options'])) {
                  $flattened[$key]['options'] = array_values($value['options']);
              }
          }
          $flattened = array_values($flattened);
  
          return $flattened;
      }
code_tokens: protected function flatten_options ( $ options , $ nothing ) { $ flattened = [ ] ; foreach ( $ options as $ value => $ option ) { if ( is_array ( $ option ) ) { foreach ( $ option as $ groupname => $ optoptions ) { if ( ! isset ( $ flattened [ $ groupname ] ) ) { $ flattened [ $ groupname ] = [ 'name' => $ groupname , 'isgroup' => true , 'options' => [ ] ] ; } foreach ( $ optoptions as $ optvalue => $ optoption ) { $ cleanedvalue = $ this -> clean_url ( $ optvalue ) ; $ flattened [ $ groupname ] [ 'options' ] [ $ cleanedvalue ] = [ 'name' => $ optoption , 'value' => $ cleanedvalue , 'selected' => $ this -> selected == $ optvalue , ] ; } } } else { $ cleanedvalue = $ this -> clean_url ( $ value ) ; $ flattened [ $ cleanedvalue ] = [ 'name' => $ option , 'value' => $ cleanedvalue , 'selected' => $ this -> selected == $ value , ] ; } } if ( ! empty ( $ nothing ) ) { $ value = key ( $ nothing ) ; $ name = reset ( $ nothing ) ; $ flattened = [ $ value => [ 'name' => $ name , 'value' => $ value , 'selected' => $ this -> selected == $ value ] ] + $ flattened ; } // Make non-associative array. foreach ( $ flattened as $ key => $ value ) { if ( ! empty ( $ value [ 'options' ] ) ) { $ flattened [ $ key ] [ 'options' ] = array_values ( $ value [ 'options' ] ) ; } } $ flattened = array_values ( $ flattened ) ; return $ flattened ; }
docstring: Flatten the options for Mustache.
  
  This also cleans the URLs.
  
  @param array $options The options.
  @param array $nothing The nothing option.
  @return array
docstring_tokens: Flatten the options for Mustache .