I have an unordered array of numbers, and I want to find where a variable sits within that range of numbers, and express it as a number between 0 and 1.
- If the variable is the highest number in the array output 1.
- If the variable is the lowest number in the array output 0.
- If the variable is midway between the highest and lowest numbers in the array output 0.5.
I was going to use min() and max() to find the highest and lowest points of the array, and then run a calculation based on that... but I'm stumped for finding where the variable sits within the array and expressing it as a number between 0 and 1.
For example:
$my_array = array( 2.51, 3.63, 10.98, 6.39, 1.54, 6.02 );
$find_this = 3.63;
function compare_to_range {
$highest = max($my_array);
$lowest = min($my_array);
Something to show where $find_this sits within those two points.
}
Something to show where $find_this sits within those two points.? Based on your above explanation, if3.63is not the highest or lowest value, you said you wanted to return0.5?