Skip to content

Instantly share code, notes, and snippets.

@walison17
Last active May 30, 2020 21:05
Show Gist options
  • Save walison17/923cd933f0c6b2756e2921adc4a3fc30 to your computer and use it in GitHub Desktop.
Save walison17/923cd933f0c6b2756e2921adc4a3fc30 to your computer and use it in GitHub Desktop.
<?php
function choices($start, $operation, $max = 999)
{
$down = $operation < 0;
$start = $down ? $start : $start + 1;
$end = $start + ($down ? $operation : $operation - 1);
$choices = [];
foreach (range($start, $end) as $i) {
$goBack = $i < 0 || $i > $max;
$base = $down ? $max + 1 : 0;
$choices[] = $goBack ? $base + $i : $i;
}
return $choices;
}
function get_interval_numbers($selected, $quantity, $max = 999)
{
return array_merge(
choices($selected, $quantity, $max),
choices($selected, $quantity * -1, $max),
);
}
echo var_dump(get_interval_numbers(20, 50));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment