-1
The goal is to find the next ordinary sequence of 03 Keys within a array with broken indexes, in the example would be 4,5,6 or 7,8,9
CODE
<?php
$myArray = array(
'item_1',
'item_2',
'item_3',
'item_4',
'item_5',
'item_6',
'item_7',
'item_8',
'item_9',
'item_10',
'item_11',
);
$arrOriginal = $myArray;
unset($myArray[2]);
unset($myArray[3]);
print_r(PHP_EOL . "Lista índices Quebrados" . PHP_EOL);
foreach ($myArray as $keyItem => $itemValue) {
echo 'Key: ' . $keyItem . ', Valor: ' . $itemValue . PHP_EOL;
}
print_r(PHP_EOL . "Lista Original" . PHP_EOL);
foreach ($arrOriginal as $keyItem => $itemValue) {
echo 'Key: ' . $keyItem . ', Valor: ' . $itemValue . PHP_EOL;
}
RETURN
Lista índices Quebrados
Key: 0, Valor: item_1
Key: 1, Valor: item_2
Key: 4, Valor: item_5
Key: 5, Valor: item_6
Key: 6, Valor: item_7
Key: 7, Valor: item_8
Key: 8, Valor: item_9
Key: 9, Valor: item_10
Key: 10, Valor: item_11
Lista Original
Key: 0, Valor: item_1
Key: 1, Valor: item_2
Key: 2, Valor: item_3
Key: 3, Valor: item_4
Key: 4, Valor: item_5
Key: 5, Valor: item_6
Key: 6, Valor: item_7
Key: 7, Valor: item_8
Key: 8, Valor: item_9
Key: 9, Valor: item_10
Key: 10, Valor: item_11
EXPECTED RESULT IN THIS EXAMPLE
4,5,6 or 7,8,9
For example if instead of
unset($myArray[2]); unset($myArray[3]);
thatunset($myArray[3]); unset($myArray[7]);
the result would be[0,1,2]
,[4,5,6]
and ,[8,9,10]
?– Augusto Vasques
Actually unset is the action of removing an item in the code, but the idea is to take only consecutive sequences of 3 indices within an array in which there will be missing indices as in the example.
– André Cabral
That I want to know if I remove those specific indices,
3
and the7
, the result will be[0,1,2]
,[4,5,6]
and[8,9,10]
or it will be something different as only the first occurrence[0,1,2]
?– Augusto Vasques
That, [0,1,2], [4,5,6] and [8,9,10]
– André Cabral
I am implementing a reserve list, in which I am generating the hours every 30 minutes, assuming that the reserve lasts 90 consecutive minutes I imagine it will take 03 indices within the array. So when the user is going to book, only the reservation that starts in the Index that contains +2 forward has to appear.
– André Cabral
Got it, at the moment I’m closing the office(wetland time zone). When you get home I give you a strength.
– Augusto Vasques