Ok i have this:
array(2, 2, 2, 2, 2, 3, 4, 2, 1, 2, 5, 5, 68);
I would like it to output:
There exists 6 x 2s in the array
1 x 3
1 x 4
2 x 5
1 x 68
How can i do this?
Have a look at the array_count_values() function.
$arr = array(2, 2, 2, 2, 2, 3, 4, 2, 1, 2, 5, 5, 68);
foreach(array_count_values($arr) as $value => $count)
{
printf("%d x %d<br />\n", $count, $value);
}
Answer is array_count_values
$array = array(2, 2, 2, 2, 2, 3, 4, 2, 1, 2, 5, 5, 68);
print_r(array_count_values($array))
Check out the documentation
Output
Array
(
[2] => 6
[3] => 1
[4] => 1
[5] => 2
[68] => 1
)