I am writing a simple PHP page reporting results from various sensors. Since the number of sensors and their locations will vary I need to account for that in my code.
$Location_Array = array('Sanding', 'Outside');
foreach($Location_Array as $Locations) {
${"Time_Array_" . $Locations} = array();//Array data fed via array_push via mysql query- clipped
}
$diff = array_diff(${"Time_Array_" . $Location_Array[0]}, ${"Time_Array_" . $Location_Array[1]});//This is the problem line - It does work
As you can see my Time_Array_LOCATION is an array that is created via an array of locations. The locations will be set by the end user via a settings file. The code does work but each location would have to be manually put into array_diff. The sensors report at specific times and if one fails to report all of the arrays will have that key/value removed. I need to have it compare all of the arrays dynamically from the Location_Array.
Like:
$diff = array_diff($Time_Array_Sanding, $Time_Array_Outside, $Time_Array_ANOTHER);
I figure it is something simple and I am just overlooking it. I thought of looping it but that returns the values not the array variable name etc... I hope this makes sense.
Thanks in advance for the help.
additional info:
The arrays are nothing more than MySQL time stamps. The times just have to match. The data is (09-20-2016 9:00, 09-20-2016 9:30) and so on. If one doesn't have the 9:00 time stamp. I drop the data for that time on all of the arrays.
$date = $row["date_time"];
$dt = substr($date, 5, 11);
array_push(${"Time_Array_" . $Locations}, $dt);
$diff? And then specify which outcome you you desire?array_intersectinstead ofarray_diff?