Skip to content

Instantly share code, notes, and snippets.

@barakpinchovski
Created September 10, 2019 17:12
Show Gist options
  • Save barakpinchovski/b4067b0682715d71e7cbece19b3417b0 to your computer and use it in GitHub Desktop.
Save barakpinchovski/b4067b0682715d71e7cbece19b3417b0 to your computer and use it in GitHub Desktop.
<?php
$arr = [1,2,3,4,5];
$d = 4;
var_dump(rotLeft($arr, $d));
function rotLeft($a, $d) {
if (gettype($a) !== 'array' || !count($a)) {
return [];
}
if (gettype($d) !== 'integer' || $d <= 0 || !($d % count($a)) ) {
return $a;
}
while ($d--) {
$n = reset($a);
unset($a[key($a)]);
array_push($a, $n);
}
return $a;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment