One way to find the range of all values in a map (associative array) in PHP is:
main.php231 chars15 lines
In this solution, we first convert the map to an indexed array of values using array_values()
function. Then we find the maximum and minimum values of the array using max()
and min()
functions respectively. Finally, we calculate the range by subtracting the minimum from maximum.
Note that this solution assumes that the map has numeric values. If the map has string values or other non-numeric values, then this solution may not work as expected.
gistlibby LogSnag