2
I have a array
with multiple schedules, may sometimes have only 4 and other N times.
I just need to get some records.
Follows my code:
$array = array(
0 => "08:00:00",
1 => "08:02:00",
2 => "08:04:00",
3 => "08:08:00",
4 => "08:10:00",
5 => "10:59:00",
6 => "11:00:00",
7 => "11:05:00",
8 => "11:11:00",
9 => "13:00:00",
10 => "13:03:00",
11 => "13:06:00",
12 => "13:08:00",
13 => "18:00:00",
14 => "18:03:00",
15 => "18:06:00",
16 => "18:35:00",
17 => "19:15:00"
);
$auxiliar = null;
foreach ($registros as $indice => $registro) {
if ($auxiliar === null) {
$auxiliar = $registro;
continue;
}
$registroAtual = current($registros); //Registro atual
$proximoRegistro = next($registros); //Proximo registro
//Tem um proximo registro
if($proximoRegistro){
//Diferença entre dois horários
$diffHorarios = $this->calculaTempo($registroAtual, $proximoRegistro);
//Houve registros no intervalo de 10 minutos
if($diffHorarios <= '00:10:00'){
unset($registros[$indice]);
}
}
}
Your routine should take the first time and add it to a variable and the list of valid times. Take the second and compare your variable plus the margin you want. If it is within that margin you discard. Read the second and do the same thing. It follows.... Reads the very same - this one outside your margin. Updates its variable and adds it to the list of valid schedules. Read the enessima + 1 and check the margin and follow. In the end you will have the list of valid schedules.
– Reginaldo Rigo
How would that look in the code ?!
– Fernanda Maria
anyone ??? help ?
– Fernanda Maria
@Lucascoelho I made an example, I hope it helps, else the right result in your question has different data so please note the array by 18:06 should not appear ! I believe not ... kkk
– novic
@Lucascoelho I will improve wait a lot I warn you.
– novic
@Virgilionovic ok, thank you!
– Fernanda Maria
@Virgilionovic Any doubt I’m at your disposal, thank you
– Fernanda Maria
@Virgilionovic It worked, thank you very much!
– Fernanda Maria