Tutorials Algorithms Analysis of Algorithms Data Structures Languages Interview Corner GATE ISRO CS UGC NET CS CS Subjects Web Technologies Student Jobs

*

*

*

*

The array_count_values() is an inbuilt function in PHP which is used to count all the values inside an array. In other words we can say that array_count_values() function is used to calculate the frequency of all of the elements of an array.

Đang xem: How to count all elements or values in an array in php

Syntax:

array array_count_values( $array )Parameters: This function accepts single parameter $array. This parameter is the array for which we need to calculate the count of values present in it.

Xem thêm:

Return Value: This function returns an associative array with key-value pairs in which keys are the elements of the array passed as parameter and values are the frequency of these elements in an array.

Xem thêm:

Note: If the element is not a string or integer then an E_WARNING is thrown.

Examples:

Input : array = (“Geeks”, “for”, “Geeks”, “Geeks”, “Welcome”, “for”)Output : Array ( => 3 => 2 => 1 )Input : array = (1, 1, 2, 3 , 1 , 2 , 4, 5)Output : Array ( <1> => 3 <2> => 2 <3> => 1 <4> => 1 <5> => 1 ) Below program illustrates the working of array_count_values() function in PHP:

// PHP code to illustrate the working
// of array_count_values() function
function Counting($array){
return(array_count_values($array));
}
// Driver Code
$array = array(“Geeks”, “for”, “Geeks”, “Geeks”, “Welcome”, “for”);
print_r(Counting($array));
?>

Output:

Array( => 3 => 2 => 1)Reference: http://php.net/manual/en/function.array-count-values.php

My Personal Notes arrow_drop_up
Save
favorite_border Like
first_page Previous
PHP | array_combine() Function
Next last_page
PHP | array_diff() function
Recommended Articles
Page :
How to get the function name inside a function in PHP ?
25, Sep 19
PHP 5 vs PHP 7
05, May 16
PHP | Get PHP configuration information using phpinfo()
08, Jan 18
PHP | php.ini File Configuration
17, Jul 19
How to import config.php file in a PHP script ?
02, Mar 20
PHP | imagecreatetruecolor() Function
18, Sep 18
PHP | fpassthru( ) Function
11, Jun 18
PHP | ImagickDraw getTextAlignment() Function
16, Dec 19
PHP | DsSequence last() Function
24, Jan 19
PHP | Imagick floodFillPaintImage() Function
30, Jul 19
Function to escape regex patterns before applied in PHP
31, Oct 19
PHP | array_udiff_uassoc() Function
11, Jul 18
PHP | geoip_continent_code_by_name() Function
01, Jul 18
PHP | GmagickPixel setcolor() function
23, Jan 20
PHP | opendir() Function
11, Jul 18
PHP | cal_to_jd() Function
30, Aug 18
PHP | stream_get_transports() Function
17, Dec 18
PHP | DsDeque pop() Function
31, Jan 19
PHP | SimpleXMLElement children() Function
27, Jun 19
PHP | array_intersect_ukey() Function
01, Jun 18
PHP | Imagick adaptiveSharpenImage() Function
06, Sep 18
PHP | XMLWriter endDtdEntity() Function
18, Mar 20
PHP | isset() Function
26, Apr 20
04, Jun 18
Article Contributed By :

*

Chinmoy Lenka
Chinmoy Lenka
Vote for difficulty
Easy Normal Medium Hard Expert
Report Issue
What’s New
Data Structures and Algorithms – Self Paced Course
View Details
Ad-Free Experience – darkedeneurope.com Premium
View Details
Most popular in PHP
Most visited in Web Technologies

Writing code in comment? Please use ide.darkedeneurope.com, generate link and share the link here.

Load Comments
5th Floor, A-118, Sector-136, Noida, Uttar Pradesh – 201305
feedback
darkedeneurope.com
Company Learn Practice Contribute
darkedeneurope.com , Some rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy Got It !

Related Post

Leave a Reply

Your email address will not be published. Required fields are marked *