- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
array_count_values() function in PHP
The array_count_values() function returns an array with the number of occurrences for each value. It returns an associative array. The returned array has keys as the array’s values, whereas values as the count of the passed values.
Syntax
array_count_values(arr)
Parameters
arr − The array for which we want to count the values.
Return
The array_count_values() function returns an associative array. The returned array has keys as the array’s values, whereas values as the count of the passed values.
Example
<?php $arr = array("Laptop","Keyboard","Mouse","Keyboard","Keyboard", "Mouse","Keyboard"); print_r(array_count_values($arr)); ?>
Output
Array ( [Laptop] => 1 [Keyboard] => 4 [Mouse] => 2 )
Advertisements