I have a foreach loop that calls a file through include:
foreach ($multiTradingPairs as $multiTradingPair) {
echo '<h1>'.$multiTradingPair['pair'].'</h2>';
include('new-trader.php');
sleep(2);
}
The include file calculates the RSI and the above foreach loop basically calculates the Relative Strength Index of three currencies based on a previous predetermined array.
My problem is that the data from the first array key is being passed onto the second one, and the data from the second one onto the third. This means that the RSI is being calculated incorrectly.
How can I reset the values in the 'include' file to start it from scratch?
Thanks
Try moving everything that you need inside of
new-trader.phpinto a function. Then, only include the file once, outside of the loop.Then, while you're iterating through the array, call the included function with an argument, which is a single
$multiTradingPair.