PHP - Function array_count_values()


Advertisements


Syntax

array array_count_values ( array $input );

Definition and Usage

Returns an array using the values of the input array as keys and their frequency in input as values.

Parameters

Sr.No Parameter & Description
1

input

The array of values to count

Return Values

Returns an associative array of values from input as keys and their count as value.

Example

Try out following example −

<?php
   $input_array = array("orange", "mango", "banan", "orange" );
   print_r(array_count_values($input_array));
?> 

This will produce the following result −

Array ( [orange] => 2 [mango] => 1 [banana => 1 )

php_function_reference.htm