Skip to content

Instantly share code, notes, and snippets.

@erlangparasu
Last active August 19, 2019 05:41
Show Gist options
  • Select an option

  • Save erlangparasu/f7f8331ae2a22ca817474614ceb4f1eb to your computer and use it in GitHub Desktop.

Select an option

Save erlangparasu/f7f8331ae2a22ca817474614ceb4f1eb to your computer and use it in GitHub Desktop.
<?php
$funArrRotate = function (&$array, $rotate_count) {
for ($i = 0; $i < $rotate_count; $i++) {
array_push($array, array_shift($array));
}
};
$numbers = [];
for ($x = 1; $x <= 12; $x++) {
$numbers[] = $x;
}
$funArrRotate($numbers, 6);
// Note: numbers value: [7,8,9,10,11,12,1,2,3,4,5,6]
// References:
// - https://stackoverflow.com/questions/5601707/php-rotate-an-array/41073285#41073285
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment