<?php
arr array_count_values ( arr $array )
where,
$array = The working array
?>
<?php
$arr01 = [ 2, 8, 18, 32, 32, 18, 8 ];
echo 'In the given ARRAY:<br>';
print_r($arr01);
echo '<br><br>';
$ctv01 = array_count_values($arr01);
foreach($ctv01 as $k01 => $v01)
{
if($v01 == 1)
{
echo 'The value ' . $k01 . ' appears ' . $v01 . ' time.<br>';
}
else
{
echo 'The value ' . $k01 . ' appears ' . $v01 . ' times.<br>';
}
}
?>
<?php
$arr02 = [ "K" => 2,
"L" => 8, "M" => 18,
"N" => 32, "O" => 32,
"P" => 18, "Q" => 8 ];
echo 'In the given ARRAY:<br>';
print_r($arr02);
echo '<br><br>';
$ctv02 = array_count_values($arr02);
foreach($ctv02 as $k02 => $v02)
{
if($v02 == 1)
{
echo 'The value ' . $k02 . ' appears ' . $v02 . ' time.<br>';
}
else
{
echo 'The value ' . $k02 . ' appears ' . $v02 . ' times.<br>';
}
}
?>
<?php
$arr03 = [ "A" => [2, 8, 18 ], "B" => [ 32, 32 ] ];
$ctv03 = array_count_values($arr03);
var_export($ctv03);
?>
<?php
$arr04 = ['South America' => 'Brazil',
'Europe' => 'Portugal',
'Asia' => 'Japan'];
$ctv04 = array_count_values($arr04);
var_export($ctv04);
?>