To find the range of all elements in an array in PHP, you can make use of the min()
and max()
functions. The range of an array is the difference between the smallest and largest values.
Here's an example code that demonstrates how to find the range of an array:
main.php320 chars11 lines
This will output:
main.php29 chars2 lines
In this example, we first define an array of numbers. We then use the min()
and max()
functions to find the smallest and largest values in the array, respectively. Finally, we calculate the difference between the largest and smallest values to obtain the range of the array.
gistlibby LogSnag