Hi folks,
Amateur coder here in need of some help.
Background: I have a dozen sensors that get recorded in a database. The sensors are not very reliable, so to smooth out the data to graph, I compare the reading to the previous reading and if they differ by a given delta I replace the reading by the previous reading (smooth out spikes). The data for each sensor is loaded into arrays that are names according to sensor numbers (ie sensor one - $sensor1, sensor 6 - $sensor6). I have go through and do the comparison on each array and just repeat the code a dozen times, but I'd like to simplify the amount of code if possible. I'm not sure how to refer to an array by using a variable.
Here is a simplified example of what I would like to do. The issue comes with - $array($i)[$x]
Hope this makes sense of what I'm tring to do. Any guidence would be greatly appreciated. Trying to become a better programmer than just repeating the same piece of code a dozen times..
<?php
//define arrays of data
$array1 = array (7,8,9,10,11,12);
$array4 = array (13,14,15,16,17,18);
$array6 = array (1,2,3,4,5,6);
//define array of sensors
$sensors = array(1, 4, 6);
//loop through each data point of each array
foreach ($sensors as $i) {
for ($x = 0; $x <= 6; $x++) {
echo $array($i)[$x];
}
}
?>