Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Count the frequency of values in an array

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 112
    Comment on it

    Hello friends,

    If you want to count all the values in an array means you want that how much time a value is exist in an array then you can use a predefined PHP function which is "array_count_values()". array_count_values() returns an array using the values of an array as keys and their frequency as values. It means this function returns an array in which value is used as key and it's counting is used as a value. Here is a example which will explain you this function-

    <?php
    $array = array("Hi",2, "hello", 2, "world", "hello");
    print_r(array_count_values($array));
    ?>
    

    Output:

    Array
    (
        [Hi] => 1
        [2] => 2
        [hello] => 2
        [world] => 1
    )
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: