PHP Exercises: Compute the difference between the largest and smallest values in a given array of integers and length one or more
107. Difference Between Largest and Smallest
Write a PHP program to compute the difference between the largest and smallest values in a given array of integers and length one or more.
Sample Solution:
PHP Code :
Sample Output:
Difference between the largest and smallest values: 11
Flowchart:

For more Practice: Solve these Related Problems:
- Write a PHP script to identify the maximum and minimum numbers in an array and compute their difference.
- Write a PHP function to traverse an array and determine the difference between its highest and lowest values.
- Write a PHP program to sort an array and then subtract the first element from the last to yield the difference.
- Write a PHP script to manually compute the range (max - min) of an array without using built-in sort functions.
Go to:
PREV : Count Even Numbers in Array.
NEXT : Sum of Array Except 17.
PHP Code Editor:
Contribute your code and comments through Disqus.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.