Coding Villa

Count values in array using array_count_values in PHP

Author : Tahreem Anwar

Share with Friends
Views : 491
Ratings : 0
Bookmarks : 0
Farourities : 0

Description


In this simple article you will learn about Count Values in array using array_count_values in PHP.


Advertisements


 

 

 

Purpose:

 

array_count_values function counts the number of value occurrence in array. It takes one parameter that is array. array_count_values(array).

 

 

Code:

 

 

1.    <?php

2.    $students=array("Rizwan","Tahreem","Fatima","Malik",

        "Rizwan","Tahreem","Malik");

3.    print_r(array_count_values($students));

4.    ?>

 

Output:

 

Array ( [Rizwan] => 2 [Tahreem] => 2 [Fatima] => 1 [Malik] => 2 )

 

Explanation:

 

In the code above on line 2 we have declared and initialize an array. Then on line 3 we have passed it to array_count_values function to count number of occurrence of the value. Then we have passed it to print_r function to show output of the array.

 



Article Tags
Share with Friends

Comments




Leave a Reply

Name (required)  
Mail (will not be published) (required)   
 
Enter This Code
Captcha
 

Advertisements

Article Categories

.NET


Databases


Mobile Development


Operating Systems


Web Development


Coding Villa on Facebook