I have a function that generates graphs passed on a "window" of dates, but it calculates moving averages so, it uses and array like this...
function generate_graph($window,$value,$percent) {
//general
$pull = 2 * $window;
$price = source_choose($value,$window);
//Data crunching
for ($i = 0 ; $i <= $window - 1 ; $i++) {
if ($window == "20") {
$working = array ($price[39 - $i], $price[38 - $i], $price[37 - $i], $price[36 - $i], $price[35 - $i], $price[34 - $i], $price[33 - $i], $price[32 - $i], $price[31 - $i], $price[30 - $i], $price[29 - $i], $price[28 - $i], $price[27 - $i], $price[26 - $i], $price[25 - $i], $price[24 - $i], $price[23 - $i], $price[22 - $i], $price[21 - $i], $price[20 - $i], $price[19 - $i]);
} elseif ($window == "5") { $working = array ($price[9 - $i], $price[8 - $i], $price[7 - $i], $price[6 - $i], $price[5 - $i], $price[4 - $i]);
}
....
as you can see I am using an if then style statement to decide which array to use. But this isn't a very flexable method, and can get veeerrrrry tedious for when you want to declare it for large window values. I need the array to start from (($pull - 1) -$i) and go to (($window - 1) - $i). I didn't really know how to go about this. Thanks for any help.