I'm attempting to pass the denominator variable to the function convert. When I do, the returned array "$new_arr" produces "0" for each value.
I have tried replacing the variable $denominator with a digit within the function and the new array returns with the appropriate numbers.
My experience with PHP is novice so my questions are:
1) Is this an issue of scoping? I thought by declaring these variables outside of the function, they were inherently global.
2) Do I need to pass '$denominator' as an argument as well?
Thanks in advance. Here's the code.
$highest_val = max($array_1);
$lowest_val = min($array_2);
$denominator = $highest_val - $lowest_val;
function convert($arr)
{
$new_arr=array();
for($i=0, $count = count($arr); $i<$count; $i++)
{
$numerator = $arr[$i]-$lowest_val;
$calc = $numerator/$denominator;
$new_arr[] .= $calc;
}
$arr = $new_arr;
return $arr;
}
$test_arr = convert($open_array);
var_dump($test_arr);