Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $arr = [7,5, 6,2,4,1,0, 12, 15, 14, 18, 20, 21, 19];
- sort($arr);
- $min = null;
- $max = null;
- $count = count($arr);
- for($index = 0; $index < $count; $index++) {
- $isLastIteration = ($count - $index === 1);
- if (!$isLastIteration and ($arr[$index] === ($arr[$index + 1] - 1))) {
- if ($min === null) {
- $min = $arr[$index];
- }
- continue;
- }
- if ($min !== null) {
- $max = $arr[$index];
- echo "$min -> $max", '<br>';
- $min = null;
- $max = null;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement