For this PHP code exercise, create a file named histogram.php
. This file should contain a function named histogram()
which accepts one parameter. This parameter must be an array.
Given an array, histogram()
will return an associative array of values from the given array as keys and their count as value.
For example, given ['a', 'a', 'b', 4]
, histogram()
should return ['a' => 2, 'b' => 1, 4 => 1]
.
Note: for this exercise, you can assume that all values within the given array are integers or strings.
Review the PHP Code Exercises documentation for more details on performing code exercises.
Jump on the PHP channel in Slack and ask your fellow students and mentors for a hint.