Skip to content

Instantly share code, notes, and snippets.

@hyperized
Last active November 9, 2019 19:27
Show Gist options
  • Save hyperized/1ac93a5a08fd46523315fc2a7983086f to your computer and use it in GitHub Desktop.
Save hyperized/1ac93a5a08fd46523315fc2a7983086f to your computer and use it in GitHub Desktop.
<?php
public static function isUpperBoundary(array $input, int $current_key, $pattern, int $steps_back): bool
{
for ($counter = $current_key - 1; $counter >= $current_key - $steps_back; $counter--) {
if (!array_key_exists($counter, $input) || $input[$counter] !== $pattern) {
return false;
}
}
return true;
}
public static function isLowerBoundary(array $input, int $current_key, $pattern, int $steps_forward): bool
{
for ($counter = $current_key + 1; $counter <= $current_key + $steps_forward; $counter++) {
if (!array_key_exists($counter, $input) || $input[$counter] !== $pattern) {
return false;
}
}
return true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment