I have two arrays, one of them contains dates with intervals of 10 min, in UNIX format and the other contains data extracted from a query, containing UNIX dates and a count, the intention is to compare both arrays in such a way that the date UNIX matches, place the value of the second array, otherwise put a zero, thus forming a list of UNIX dates with their respective value as appropriate.
this is my code in PHP (codeiginiter 3):
//My first array
$fecha1 = "2017-12-01 00:00:00";
$fecha2 = "2017-12-31 23:59:59";
//-----
$date = array();
$data_final = array();
for($i=$fecha1;$i<=$fecha2;$i = date("Y-m-d H:i:s", strtotime($i ."+ 10
minutes"))){
$date_unix[strtotime($i)] = 0; //convierte a unix
}
//My second array from datebase
$datos = $this->statistics_model->get_sample();
$result_model = array();
foreach ($datos as $dato) {
$result_model[(int)$dato->unix] = (int)$dato->resta;
}
Example result of second array
Aucun commentaire:
Enregistrer un commentaire