PHP PHP Interview

How do I count the occurrence of duplicate items in the array

Pinterest LinkedIn Tumblr
<?php
$input= array(10,101,21,01,11,12,12131,14,115,51,51);

$count_values = array();

foreach ($input as $a) {
   $count_values[$a]++;
}

echo 'Duplicates count: '.count($count_values);
print_r($count_values);

?>

Write A Comment

Open chat
Hey Visitor,

How can I help you?