所以我有這個函數(裏面的東西不是很重要,因爲它的工作原理),並且當我打印底部的任何數組時例如$ stdDevArraycomparison),它可以工作。但是,如果我調用函數,然後嘗試打印數組,它不會執行任何操作。爲什麼在調用函數後無法打印數組?爲什麼我不能打印在函數外創建的數組
function TickerResearch ($results, $period, $volinterval) {
for ($x = 2; $x < count($resultscomparison) - 1; $x++) {
$residualsArraycomparison[$x - 2] = round(($resultscomparison[$x]/$resultscomparison[$x + 1]) - 1, 5); // this is the residuals array that I will use for RSI along with the histograms.
}
for ($x = 0; $x < count($residualsArraycomparison) - $period; $x++) {
for ($y = 0; $y < $period; $y++) {
if ($residualsArraycomparison[$x + $y] > 0) {
$upcomparison[$x]++; // no need to define it as 0 beforehand.
}
}
}
for($x = 2; $x < count($resultscomparison) - $period; $x++) {
for ($y = 0; $y < $period; $y++) {
$residualscomparison[$y] = ($resultscomparison[$x + $y]/$resultscomparison[$x + $y + 1]) - 1;
}
$residualsAverage = array_sum($residualscomparison)/count($residualscomparison);
for ($y = 0; $y < $period; $y++) {
$residualsSub[$y] = pow($residualscomparison[$y] - $residualsAverage, 2); // for std dev
$third_moment[$y] = pow($residualscomparison[$y] - $residualsAverage, 3); // for skewness
$fourth_moment[$y] = pow($residualscomparison[$y] - $residualsAverage, 4); // for kurtosis
}
$third_momentSum = array_sum($third_moment);
$fourth_momentSum = array_sum($fourth_moment);
$variance = array_sum($residualsSub)/count($residualsSub);
$stdDevArraycomparison[$x] = pow($variance, 0.5);
$skewnessArraycomparison[$x] = $third_momentSum/(($period - 1) * pow($stdDevArraycomparison[$x], 3)); // | These are both similar. Kurtosis is calculated on
$kurtosisArraycomparison[$x] = ($fourth_momentSum/(($period - 1) * pow($stdDevArraycomparison[$x], 4)) - 3); // | fours while skewness is calculated on threes.
}
for ($x = 0; $x < count($upcomparison); $x++) {
$upArraycomparison[$x] = 100 - 100/(1 + ($upcomparison[$x]/($period - $upcomparison[$x])));
}
// print_r($stdDevArraycomparison) would work here.
}
TickerResearch($results, $period, $volinterval);
// print_r($stdDevArraycomparison) WON'T work here.
這實際上並不是我想要的,因爲我必須輸出四個不同的數組。 –