arrayutils
  • Home
  • đź“–How to use?
    • ⚡Installation
  • đź“–Methods
    • ⚡Static method
      • static from()
      • static of()
      • static mapToArray()
    • ⚡Generic method
      • join()
      • every()
      • some()
      • reduce()
        • reduceRight()
      • sum()
      • pop()
      • shift()
      • includes()
      • keyExists()
      • indexOf()
      • find()
        • findIndex()
      • first()
        • keyFirst()
      • last()
        • keyLast()
      • random()
        • keyRandom()
      • splice()
    • ⚡Chain method
      • chunk()
      • column()
      • combine()
      • concat()
        • concatSoft()
      • countValues()
      • diff()
        • diffAssoc()
        • diffKey()
      • fill()
        • fillKeys()
      • filter()
      • flat()
        • flatMap()
      • flip()
      • forEach()
      • intersect()
        • intersectAssoc()
        • intersectKey()
      • keys()
      • map()
        • mapAssoc()
        • mapKey()
      • pad()
      • push()
      • replace()
      • reverse()
      • slice()
      • sort()
        • sortKey()
      • unique()
      • unshift()
      • values()
  • đź“–Suffixes
    • ⚡Suffix - From
    • ⚡Suffix - As
  • links
    • 📌Github repo
    • 📌Packagist project
    • 📌Poggit project
Powered by GitBook
On this page
  • Syntax
  • Return value
  • Polymorphism
  • References
  1. đź“–Methods
  2. ⚡Chain method

countValues()

The countValues() method counts all the values of an array

Example.php
<?php use kim\present\utils\arrays\ArrayUtils;

$arrayUtils = ArrayUtils::from(["a", "a", "a", "b", "c", "c", "d"]);

//General usage
$arrayUtils->countValues();
// expected output: ["a" => 3, "b" => 1, "c" => 2, "d" => 1]

Syntax

$arrayUtils->countValues() : ArrayUtils;

Return value

  • A associative array of values from array as keys and their count as value.

Polymorphism

$arrayUtils->countValuesAs() : array;
ArrayUtils::countValuesFrom(iterable $from) : ArrayUtils;
ArrayUtils::countValuesFromAs(iterable $from) : array;

References

PreviousconcatSoft()Nextdiff()

Last updated 4 years ago

PHP: array_count_values - Manual
Logo