function array_count_values_of($value, $array) {
    $counts = array_count_values($array);
    return $counts[$value];
}

Not native, but come on, it's simple enough. ;-)

Alternatively:

echo count(array_filter($array, function ($n) { return $n == 6; }));

Or:

echo array_reduce($array, function (n) { return n == 6); }, 0);

Or:

echo count(array_keys($array, 6));
Answer from deceze on Stack Overflow
🌐
PHP
php.net › manual › en › function.array-count-values.php
PHP: array_count_values - Manual
array_count_values — Counts the occurrences of each distinct value in an array · function array_count_values(array $array): array · array_count_values() returns an array using the values of array (which must be ints or strings) as keys and ...
🌐
Codecademy
codecademy.com › docs › php › arrays › array_count_values()
PHP | Arrays | array_count_values() | Codecademy
August 8, 2023 - The array_count_values() is a function that counts the occurrences of values in an array. It accepts an input array and returns an associative array, where the keys are the unique values found in the array, and the corresponding values are the ...
🌐
TutorialKart
tutorialkart.com › php › php-count-occurrences-of-specific-value-in-array
Count Occurrences of Specific Value in Array in PHP
May 8, 2023 - To count the number of occurrences of a specific value in given array in PHP, we can use count() and array_filter() functions.
🌐
Tutorialdeep
tutorialdeep.com › knowhow › php faqs › how to count occurrence of value in array in php
How to Count Occurrence of Value in Array in PHP
August 5, 2021 - When you have a given element to count its occurrence in an array, you can use the array_keys() inside the count() in PHP. You will get the result that displays the number of times the specified element is present in an array.
🌐
TutorialKart
tutorialkart.com › php › php-array-count-values
PHP array_count_values() - Count all the occurrences of values in array - Examples
May 7, 2023 - PHP array_count_values() function counts the occurrences of all values in an array and returns an associative array formed by the unique value of input array as keys, and the number of their occurrences in the array as values.
🌐
W3Schools
w3schools.com › Php › func_array_count_values.asp
PHP array_count_values() Function
connection_aborted() connection_status() connection_timeout() constant() define() defined() die() eval() exit() get_browser() __halt_compiler() highlight_file() highlight_string() hrtime() ignore_user_abort() pack() php_strip_whitespace() show_source() sleep() sys_getloadavg() time_nanosleep() time_sleep_until() uniqid() unpack() usleep() PHP MySQLi · affected_rows autocommit change_user character_set_name close commit connect connect_errno connect_error data_seek debug dump_debug_info errno error error_list fetch_all fetch_array fetch_assoc fetch_field fetch_field_direct fetch_fields fetch_l
Find elsewhere
🌐
W3Resource
w3resource.com › php-exercises › php-array-exercise-37.php
PHP Array Exercise: Count the total number of times a specific value appears in an array - w3resource
... <?php // Define a function to count occurrences of a value in an array function count_array_values($my_array, $match) { $count = 0; // Iterate through each element in the array foreach ($my_array as $key => $value) { // Check if the current ...
🌐
Plus2Net
plus2net.com › php_tutorial › array_count_values.php
array_count_values: counting the frequency of elements inside array
We can count the number of time elements are present inside an array by using array_count_values function in php. This function returns another array which stores the values ( or elements ) of the input array and its frequency or the number ...
🌐
GeeksforGeeks
geeksforgeeks.org › php › count-frequency-of-an-array-item-in-php
Count Frequency of an Array Item in PHP - GeeksforGeeks
July 23, 2025 - The array_reduce() function reduces the array to a single value using a callback function, making it a powerful tool for various array manipulations, including counting frequencies.
🌐
IncludeHelp
includehelp.com › php › array_count_values-function.aspx
PHP Array array_count_values() Function (With Examples)
In this tutorial, we will learn about the PHP array_count_values() function with its usage, syntax, parameters, return value, and examples. By IncludeHelp Last updated : December 31, 2023 · The array_count_values() function will count the occurrences of each individual element and returns ...
🌐
ZetCode
zetcode.com › php-array › array-count-values
PHP array_count_values - Counting Array Values in PHP
This example shows how to count occurrences of integer values in an array. ... <?php $numbers = [1, 2, 3, 2, 1, 1, 1, 3]; $counts = array_count_values($numbers); print_r($counts);
🌐
IncludeHelp
includehelp.com › php › find-the-occurrences-of-a-given-element-in-an-array.aspx
PHP | Find the occurrences of a given element in an array
<?php //an array of the string elements $array = array( "The", "Quick", "Brown", "Fox", "Jumps", "Right", "Over", "The", "Lazy", "Dog", ); //word/element to find the the array $word = "The"; //finding the occurances $wordCount = count(array_keys($array, $word)); //printing the result echo "Word ...
🌐
Sling Academy
slingacademy.com › article › php-how-to-count-the-occurrences-of-an-array-value
PHP: How to Count the Occurrences of an Array Value - Sling Academy
Another way to count occurrences, particularly of a single value, is to use the array_filter function combined with the count function. The array_filter function filters elements of an array using a callback function, and the count function simply counts the number of elements in an array.
🌐
CodeSignal
codesignal.com › learn › courses › php-associative-arrays-in-practice-revision-and-application › lessons › efficient-element-counting-with-associative-arrays-in-php
Efficient Element Counting with Associative Arrays in PHP
When the above PHP code executes, it displays the counts for each color: ... We began with an empty associative array. Then, we went through our list, and for every occurring element, we simply incremented its value in the associative array.