Sum of data from an array using condition

1

I'm developing a system, and I'm doing the following test.

In the case, I have a number of records regarding the drop of links and I need to add these results if the difference between them is less than 24 hours, and present the date of beginning of the fall of the first record with the closing of the last record within this period. I even managed to be part of the test and add the first two elements of the vector, but when requesting the others, it error.

What can be done in this case, here is the code snippet and the part that I am wrapping

<?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 calculates the difference

In this case, it will have to display only two lines

in the First line it would show the start position [1], closing position [4] and would add the 1 to 4 positions of unavailable time. The second line would be composed with all five positions.

What can be done in this case?

    
asked by anonymous 28.03.2018 / 05:34

0 answers