Skip to content

Instantly share code, notes, and snippets.

@elchroy
Created August 1, 2019 08:46
Show Gist options
  • Save elchroy/3d356012cd363f0b3bb3a62d6ad9b39c to your computer and use it in GitHub Desktop.
Save elchroy/3d356012cd363f0b3bb3a62d6ad9b39c to your computer and use it in GitHub Desktop.
<?php
function reverseArray($a) {
$len = count($a);
$i = 0;
$res = [];
while ($i < $len) {
$j = abs($i - $len) - 1;
$res[] = $a[$j];
$i++;
}
return $res;
}
print_r(reverseArray([1, 4, 5, 2, 5, 9, 2, 4, 7, 0]));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment