Skip to content

Instantly share code, notes, and snippets.

@paveleremin
Last active August 29, 2015 14:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save paveleremin/f3745468e48253fd3e08 to your computer and use it in GitHub Desktop.
Save paveleremin/f3745468e48253fd3e08 to your computer and use it in GitHub Desktop.
Implement array_reverse() without creating new array and usage of array_pop() array_shift()
function array_reverse($arr) {
$length = count($arr);
for ($i=0; $i < $length/2; $i++) {
$tmp = $arr[$i];
$arr[$i] = $arr[$length - 1 - $i];
$arr[$length - 1 - $i] = $tmp;
}
}
var_dump(array_reverse([1,2,3,4,5]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment