How to use array count values in PHP

In this article, I will explain how the array_count_values() function can be used in PHP.
  • 2177

array_count_values() function in PHP

  • The array_count_values() function returns an array using the values of the input array as keys and their frequency in input as values.

  • The array_count_values() function is used to count all the values of an array.

Syntax

array_count_values(array)

Parameter

  • array array is required parameter.the specified array whose values are to be counted.

Example

The following example show to how the array_count_values() function can be used in PHP.

<h3 style="color:blue;">array_count_values() function example in PHP</h3>
<?php
$a=array("Manish","Aman","Manish","Nitin","Aman");
print_r(array_count_values($a));
?>

 

Output

count.jpg

You may also want to read these related articles here
 
Ask Your Question 
 
Got a programming related question? You may want to post your question here
 

Categories

More Articles

© 2019 DotNetHeaven. All rights reserved.