0
I have an array with available schedules, being these schedules in a 30 minute interval:
$arrHoras = ["08:30", "09:00", "09:30", "10:00", "10:30", ... , "18:30", "19:00"];
After some filters that are reserved schedules, I have the following array:
$arrHoras = array(
2 => "09:00",
3 => "09:30",
6 => "11:00",
7 => "11:30",
10 => "13:00",
11 => "13:30",
12 => "14:00",
13 => "14:30",
16 => "16:00",
17 => "16:30",
21 => "18:30"
);
What I need to do is make one more filter by removing times that do not satisfy a number of consecutive periods required. All of them meet the 1 that is himself, but if it is two I need it and one more time in a row, and can not jump, for example, from 9 to 9:30 ok, but from 9:30 to 11 no, because jumps the sequence.
If I need 2 schedules then the return would be this:
$arrHoras = array(
2 => "09:00",
6 => "11:00",
10 => "13:00",
11 => "13:30",
12 => "14:00",
16 => "16:00"
);
But if I need 3 times then the return would be:
$arrHoras = array(
10 => "13:00",
11 => "13:30"
);
And if I need 4 or more times will return me an empty array.
A question, if that array were ordered you would want that
$qtdeSlots
is the interval between the keys of the array's?– Erlon Charles
Example: in a array ordered where the
$qtdslots
for 2 the order of the keys was to be0,2,4,6,8...
, if$qtdslots
for 30,3,6,9,12...
and so on. That’s it?– Erlon Charles
So, not quite this, every slot of mine is 30 minutes. I can see even by the keys the count because initially I create this Arras dynamically and have all keys in order but with the filters will removing the hours that are not necessary, I only have to remove by the slots Qtde.
– Marcelo Diniz
Fine, but if each slot you own is 30 minutes, the key element 11 of array should in the answer, because he does not obey this rule.
– Erlon Charles
What happens if
$qtdeSlots
is equal to 2, for example, I need 2 slots of 30 minutes in a row to be able to accept. I have the 9:00 and 9:30, so I have 2 slots in a row, so the 9:00 is accepted, then I have the 9:30 and the 11:00 are not two in a row, so the 9:30 is not accepted, and so I do until the end. I hope I’ve been a little clearer– Marcelo Diniz
You’re still confused. Can you edit the question by zooming in on the context, all of a sudden even posting more code from how you get to that filtered array? Suddenly there’s a simpler alternative...
– Bruno Augusto
You need all intervals where the
$qtdeSlots
is equal to 2 (or number q vc put) or needs it to be greater than or equal to 2?– Erlon Charles