code: private static function collectErrors($models, $encode, $showAllErrors)
      {
          $lines = [];
          if (!is_array($models)) {
              $models = [$models];
          }
  
          foreach ($models as $model) {
              $lines = array_unique(array_merge($lines, $model->getErrorSummary($showAllErrors)));
          }
  
          // If there are the same error messages for different attributes, array_unique will leave gaps
          // between sequential keys. Applying array_values to reorder array keys.
          $lines = array_values($lines);
  
          if ($encode) {
              foreach ($lines as &$line) {
                  $line = Html::encode($line);
              }
          }
  
          return $lines;
      }
docs: Return array of the validation errors
  @param Model|Model[] $models the model(s) whose validation errors are to be displayed.
  @param $encode boolean, if set to false then the error messages won't be encoded.
  @param $showAllErrors boolean, if set to true every error message for each attribute will be shown otherwise
  only the first error message for each attribute will be shown.
  @return array of the validation errors
  @since 2.0.14