Basically, I am fetching data from an API and that API has duplicate numbers. I want to count the duplicate numbers within the foreach
, but its not working for some reason. I am not sure what I am doing wrong. You can see there is 33
many times. See the picture how it prints. It should be showing something like this
Array
(
[33] => 5
[2] => 3
)
Code:
foreach ($parsed_json1->numbers as $item) {
$ui = $item->no;
$currentp= number_format($ui, 6);
//echo $currentp;
//echo "</br>";
$array = array($currentp);
$vals = array_count_values($array);
//echo 'No. of NON Duplicate Items: '.count($vals).'<br><br>';
print_r($vals);
}