You can use the function array_filter to make the calculation. In PHP, even if it is string it is possible to make comparisons:
$horas = array_filter($array, function ($hora) use ($inicio, $fim) {
return $hora >= $inicio && $hora <= $fim;
});
This function will create a new array based on the result of the boolean expression returned by the function. If true, the item is kept in the array. If false, it is ignored.
It is important to note that keys are kept when you use array_filter. In case you need to reorder the array, you can call array_values to solve the problem:
$horas = array_filter($array, function ($hora) use ($inicio, $fim) {
return $hora >= $inicio && $hora <= $fim;
});
$horas = array_values($horas);
all array elements will be hours?
– Jeferson Almeida
yes bro. exactly.
– MichaelCosta