How can I use array_push
to add a timestamp and a value to a two-dimensional array with square bracket syntax?
I successfully get rows, each with a timestamp and associated value from a mysql
database.
While retrieving the results, I add these times and values into an array like so:
while($row=mysqli_fetch_array($r, MYSQLI_ASSOC)){
$q1_array[$i][0]= $row["time"];
$q1_array[$i][1]= $row["val"]; // the value ("val") will either be 1 or 0 (ON or OFF)
$i++;
}
I need the final array to contain an even number of elements (which will be within a time interval of 30 minutes), so I test for that:
If the LAST array element(s?) has a timestamp and associated value of 1
, I want to append at the end of the array the ending half-hour timestamp along with a 0
.
if ($q1_array[sizeof($q1_array)-1][1] == 1){
//here I want to append a timestamp and value
}
On the other hand, if the FIRST element(s?) has a timestamp with associated value of 1
, I want to append at the beginning of the array the starting half-hour timestamp along with a 0
.
else if ($q1_array[0][1]== 1){
//here I want to append a timestamp and value
}
Really would appreciate help! Thank you!