SQL PHP HTML ASP JavaScript articles and free scripts to download
 

Frequency of values inside an array

We can count the number of time elements are present inside an array by using array_count_values function in php. This function returns another array which stores the values ( or elements ) of the input array and its frequency or the number of occurrence of the value.

This function array_count_values works similar to group by sql query where we collect unique records with number of occurrence in a table

Here is the syntax of this function.

$result= array_count_values ($input_array)


Let us try one example to understand how this works.

$a1=array("first", "second", "third","fourth","fifth","second","third");
$new_array=array_count_values($a1);

while (list ($key, $val) = each ($new_array)) {
echo "$key -> $val <br>";
}


The output of above code will be

first -> 1
second -> 2
third -> 2
fourth -> 1
fifth -> 1






periyasamy01-01-2010
Hi Friends,...i am new to php,..i have problem taking list box value.While loop i have 5 select box, need to pass whole value into single submissio n ,..how to pass,,please help me
thanks
periyasamy
Post Comment This is for short comments only. Use the forum for more discussions.
Name
Email( not to be displayed)Privacy Policy
1+2=This is to prevent automatic submission by spammers. Please enter the result of the sum as asked


Join Our Email List
Email:  
For Email Newsletters you can trust
Array Functions
PHP Sections