1
I’m developing a system, and I’m doing the following test.
In this case, I have a number of records related to the drop of links and I need to add these results if the difference between them is less than 24 hours, and present the start date of the fall of the first record with the closing of the last record in this period. I even managed to be part of the test and add up the first two elements of the vector, but when requesting the others, it error.
What can be done in this case, follows below the excerpt of the code and the part I’m stuck
<?Php
error_reporting(E_ERROR);
$inicio = array("2018-03-02 00:04","2018-03-02 00:25","2018-03-02 01:04","2018-03-02 01:34","2018-03-01 00:24");
$fechamento = array("2018-03-02 00:19","2018-03-02 00:56","2018-03-02 01:31","2018-03-02 02:00","2018-03-11 00:27");
$tempo_indisponivel = array("00:08:04","00:05:04","00:02:02","00:07:56","00:03:11");
$horasLenght = count($inicio); //Conta a quantidade de registros no vetor
for($x = 0; $x < $horasLenght; $x++) {
$y = $x - 1 //Cria um segundo indice para fazer o teste
//Transforma o array de tempo indisponível em segundos
$seg_x = strtotime('1970-01-01'.$tempo_indisponivel[$x].'UTC');
//Inicia o teste
if($y < 0) {
echo $seg_x."____".$x."<b>XXX</b>";
} else {
echo $seg_x."____".$x."<b>XXX</b>";
$diferenca = strtotime($inicio[$x]) - strtotime($inicio[$y]);
if($diferenca < 86400) {
//Aqui que começa a duvida
}
}
}
?>
Doubt is in the second if that makes the difference calculation
In case, it will have to present only two lines
on the first line it would show the starting position[1], closing position[4], and sum the positions from 1 to 4 of unavailable time. The second line would be composed with all five positions.
What can be done in this case?