smith.james0 Posted February 16, 2017 Share Posted February 16, 2017 Hi, I am sure that the solution is easy but it's flummoxed me! I have a python script that sometimes doesn't record the temperature so I end up with 23 readings instead of 24 per day, or less. My php script reads the date from the db and puts it into a array to use in a graph. My problem is that I need to check the correct temperature reading go with the correct hour of the day. Array ( [0] => Array ( [0] => 00 [1] => 4.30 ) [1] => Array ( [0] => 01 [1] => 4.30 ) [2] => Array ( [0] => 02 [1] => 4.10 ) [3] => Array ( [0] => 03 [1] => 4.00 ) [4] => Array ( [0] => 05 [1] => 3.70 ) etc etc.. Above [0][0] is the time and [0][1] is the temperature, what I need is for the time to match the array key. So in [4][0] the time is 05 but the key is 04 i.e... Array ( [0] => Array ( [0] => 00 [1] => 4.30 ) [1] => Array ( [0] => 01 [1] => 4.30 ) [2] => Array ( [0] => 02 [1] => 4.10 ) [3] => Array ( [0] => 03 [1] => 4.00 ) [4] => Array ( [0] => 04 [1] => ) [5] => Array ( [0] => 05 [1] => 3.70 ) This is the code I use to make the array while($row = $result->fetch_array()) { $inside[] = $row; $date = strtotime($inside[$i][Time]); $inside[$i][4] = date('G', $date); $inside[$i][2] = $inside[$i][0]; unset($inside[$i][Temp]); unset($inside[$i][Time]); unset($inside[$i][1]); unset($inside[$i][0]); ++$i; } I can get it to check the time against the key, but I can not get it to correct the key to the time. Can anyone help?? Many thanks James Quote Link to comment Share on other sites More sharing options...
Barand Posted February 16, 2017 Share Posted February 16, 2017 Keep it simple $inside = []; while($row = $result->fetch_array()) { $hour = date('G', strtotime($row['time'])); $inside[$hour] = $row['temp']; } Quote Link to comment Share on other sites More sharing options...
smith.james0 Posted February 17, 2017 Author Share Posted February 17, 2017 Thanks, do you have any ideas how I could check my array so the hour matches the array key? James Quote Link to comment Share on other sites More sharing options...
Barand Posted February 17, 2017 Share Posted February 17, 2017 It's guaranteed with my code - the hour is the array key Quote Link to comment Share on other sites More sharing options...
smith.james0 Posted March 18, 2017 Author Share Posted March 18, 2017 I have only just got round to changing it, thanks Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.