Created
September 10, 2019 17:12
-
-
Save barakpinchovski/b4067b0682715d71e7cbece19b3417b0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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