find the range of a list of numbers in php

To find the range of a list of numbers in PHP, you can use the max and min functions to find the largest and smallest values, and then subtract them to get the range. Here's an example code:

main.php
$numbers = array(3, 5, 8, 2, 9, 4);
$range = max($numbers) - min($numbers);
echo "The range of the numbers is: " . $range;
123 chars
4 lines

This code creates an array of numbers and then calculates the range by subtracting the smallest value (2) from the largest value (9). The result is then echoed out to the screen. You can substitute your own array of numbers for the $numbers variable to calculate the range of your own data.

related categories

gistlibby LogSnag