Wednesday, 24 September 2014

array_count_values in PHP

PHP array_count_values() function returns an associative array. Each key in the resulting array represents a value of the input array and its corresponding value refers the number of occurrences of particular value in the input array.

Syntax:array_count_values(array)

Parameter Description:
array : Required. Specifying an array.

Example:
<?php
$days = array("Sunday","Monday","Sunday","Wednesday");
print_r( array_count_values($days) );
?>

Output:


Array ( 
           [Sunday] => 2
           [Monday] => 1
           [Wednesday] => 1
        )

0 comments:

Post a Comment