Skip to content

Instantly share code, notes, and snippets.

@aaroncampbell
Created August 17, 2016 20:37
Show Gist options
  • Save aaroncampbell/33e02870e42e1b4f2b9fdcdcf220206f to your computer and use it in GitHub Desktop.
Save aaroncampbell/33e02870e42e1b4f2b9fdcdcf220206f to your computer and use it in GitHub Desktop.
<?php
function reverse( $arr ) {
$len = count( $arr );
for ( $i = 0; $i < $len/2; $i++ ) {
list( $arr[$i], $arr[$len-$i-1] ) = array( $arr[$len-$i-1], $arr[$i] );
}
return $arr;
}
$test = array('a', 'b', 'c', 'd', 'e');
var_dump( reverse( $test ) );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment