How many times a particular value exists in an array?


A simple function solve this question using only native php functions.

Declare and invoke this function

 

<?php
function count_value_in_array ($my_value, $array)
{
    $count = 0;
   
    foreach ($array as $key => $value)
    {
        if ($value == $my_value)
        {
            $count++;
        }
    }
   
    return $count;
}
?>

Related articles