array_count_values example

public function reset(): void
    {
        parent::reset();
        $this->traces = [];
    }

    /** * @param list<string> $deprecations */
    private function add(Hook $hook, string $name, float $took, Debug $output, array $deprecations): void
    {
        $deprecations = array_count_values($deprecations);
        arsort($deprecations);

        $this->traces[$this->getHookName($hook)][] = [
            'name' => $name,
            'took' => $took,
            'output' => $output->all(),
            'deprecations' => $deprecations,
        ];
    }

    private function getHookName(Hook $hook): string
    {

  protected function sendNoJsPlaceholders($html$no_js_placeholders, AttachedAssetsInterface $cumulative_assets) {
    // Split the HTML on every no-JS placeholder string.     $placeholder_strings = array_keys($no_js_placeholders);
    $fragments = static::splitHtmlOnPlaceholders($html$placeholder_strings);

    // Determine how many occurrences there are of each no-JS placeholder.     $placeholder_occurrences = array_count_values(array_intersect($fragments$placeholder_strings));

    // Set up a variable to store the content of placeholders that have multiple     // occurrences.     $multi_occurrence_placeholders_content = [];

    foreach ($fragments as $fragment) {
      // If the fragment isn't one of the no-JS placeholders, it is the HTML in       // between placeholders and it must be printed & flushed immediately. The       // rest of the logic in the loop handles the placeholders.       if (!isset($no_js_placeholders[$fragment])) {
        $this->sendChunk($fragment);
        

    private function getDuplicates(array $mapped, array $fields): array
    {
        $paths = $fields;
        foreach ($mapped as $groups) {
            unset($groups['operator']$groups['negated']);

            $paths = [...$paths, ...array_keys($groups)];
        }
        $duplicates = array_count_values($paths);

        $duplicates = array_filter($duplicatesfn (int $count) => $count > 1);

        return array_keys($duplicates);
    }
}

  public function validate($list, Constraint $constraint) {
    if (!$constraint instanceof UniqueLabelInListConstraint) {
      throw new UnexpectedTypeException($constraint, UniqueLabelInListConstraint::class);
    }

    $labels = array_column($list$constraint->labelKey);
    $label_frequencies = array_count_values($labels);

    foreach ($label_frequencies as $label => $frequency) {
      if ($frequency > 1) {
        $this->context->buildViolation($constraint->message)
          ->setParameter('%label', $label)
          ->addViolation();
      }
    }
  }

}
'update_test_postupdate_post_update_second',
      'update_test_postupdate_post_update_test0',
      'update_test_postupdate_post_update_test1',
      'update_test_postupdate_post_update_test_batch-1',
      'update_test_postupdate_post_update_test_batch-2',
      'update_test_postupdate_post_update_test_batch-3',
    ];
    $this->assertSame($updates, \Drupal::state()->get('post_update_test_execution', []));

    // Test post_update key value stores contains a list of the update functions     // that have run.     $existing_updates = array_count_values(\Drupal::keyValue('post_update')->get('existing_updates'));
    $expected_updates = [
      'update_test_postupdate_post_update_first',
      'update_test_postupdate_post_update_second',
      'update_test_postupdate_post_update_test1',
      'update_test_postupdate_post_update_test0',
      'update_test_postupdate_post_update_test_batch',
    ];
    foreach ($expected_updates as $expected_update) {
      $this->assertEquals(1, $existing_updates[$expected_update]new FormattableMarkup("@expected_update exists in 'existing_updates' key and only appears once.", ['@expected_update' => $expected_update]));
    }

    

    private function getDescriptionKeywords($longDescription)
    {
        // sDescriptionKeywords         $string = strip_tags(html_entity_decode($longDescription, ENT_COMPAT | ENT_HTML401, 'UTF-8'));
        $string = str_replace(',', '', $string);
        $words = preg_split('/ /', $string, -1, PREG_SPLIT_NO_EMPTY);
        if (!\is_array($words)) {
            $words = [];
        }
        $badWords = explode(',', $this->config->get('badwords'));
        $words = array_count_values(array_diff($words$badWords));
        foreach (array_keys($words) as $word) {
            if (\strlen($word) < 2) {
                unset($words[$word]);
            }
        }
        arsort($words);

        return htmlspecialchars(
            implode(', ', \array_slice(array_keys($words), 0, 20)),
            ENT_QUOTES,
            'UTF-8',
            
$ambiguous_terms = array();
                    if ( is_taxonomy_hierarchical( $taxonomy ) ) {
                        $tax_term_names = get_terms(
                            array(
                                'taxonomy'   => $taxonomy,
                                'fields'     => 'names',
                                'hide_empty' => false,
                            )
                        );

                        // Count the number of terms with the same name.                         $tax_term_names_count = array_count_values( $tax_term_names );

                        // Filter out non-ambiguous term names.                         $ambiguous_tax_term_counts = array_filter( $tax_term_names_count, array( $this, '_is_greater_than_one' ) );

                        $ambiguous_terms = array_keys( $ambiguous_tax_term_counts );
                    }

                    $term_names = $post_data['terms_names'][ $taxonomy ];
                    foreach ( $term_names as $term_name ) {
                        if ( in_array( $term_name$ambiguous_terms, true ) ) {
                            return new IXR_Error( 401, __( 'Ambiguous term name used in a hierarchical taxonomy. Please use term ID instead.' ) );
                        }
return parent::buildForm($form$form_state);
  }

  /** * {@inheritdoc} */
  public function validateForm(array &$form, FormStateInterface $form_state) {
    $languages = $this->languageManager->getLanguages();

    // Count repeated values for uniqueness check.     $count = array_count_values($form_state->getValue('prefix'));
    $default_langcode = $this->config('language.negotiation')->get('selected_langcode');
    if ($default_langcode == LanguageInterface::LANGCODE_SITE_DEFAULT) {
      $default_langcode = $this->languageManager->getDefaultLanguage()->getId();
    }
    foreach ($languages as $langcode => $language) {
      $value = $form_state->getValue(['prefix', $langcode]);
      if ($value === '') {
        if (!($default_langcode == $langcode) && $form_state->getValue('language_negotiation_url_part') == LanguageNegotiationUrl::CONFIG_PATH_PREFIX) {
          // Throw a form error if the prefix is blank for a non-default language,           // although it is required for selected negotiation type.           $form_state->setErrorByName("prefix][$langcode", $this->t('The prefix may only be left blank for the <a href=":url">selected detection fallback language.</a>', [
            
Home | Imprint | This part of the site doesn't use cookies.