You can use array_count_values function
$array = array('apple', 'orange', 'pear', 'banana', 'apple',
'pear', 'kiwi', 'kiwi', 'kiwi');
print_r(array_count_values($array));
will output
Array
(
[apple] => 2
[orange] => 1
[pear] => 2
etc...
)
More Related Contents:
- Get count of each unique value in one column of a 2d array
- Group 2d array’s row data by one column and sum another column within each group to produce a reduced 2d array
- Group rows in a 2d array and count number of rows in each respective group
- How to count the consecutive duplicate values in an array?
- Pass Multi Values to PHP Variable and set this value to HTML input field
- Insert array into MySQL database with PHP
- Using $_POST to get select option value from HTML
- Using an array as needles in strpos
- How to detect duplicate values in PHP array?
- PHP reindex array? [duplicate]
- Sort php multidimensional array by sub-value [duplicate]
- Array as session variable
- Transpose 2d array, join second level with commas, and join first level with pipes
- MySQLi Bind Param with an array for IN [duplicate]
- Delete element from multidimensional-array based on value
- Search for PHP array element containing string [duplicate]
- Merge two arrays containing objects and remove duplicate values
- Deep recursive array of directory structure in PHP
- String contains any items in an array (case insensitive)
- Using value of a column as index in results using PDO
- Re-index numeric array keys [duplicate]
- Reverse array in php
- Find number which is greater than or equal to N in an array
- php split array into smaller even arrays
- How does array_diff work?
- How to iterate through a nested stdClass? [duplicate]
- How to get the object or class name?
- PHP convert nested array to single array while concatenating keys?
- Group array data on one column and sum data from another column to form a flat associative array
- PHP: Check for duplicate values in a multidimensional array