var arr = new Array( "I", "learn", "JavaScript" );
arr.reverse(); // array now modified
alert( arr.join("\n") ); // Show one element per line; click to run ->
var arr = new Array( "I", "learn", "JavaScript" );
var arr2 = arr.slice(0); // Create duplicate array
arr2.reverse(); // Copy now modified
alert( "New array:\n" + arr2.join("\n") ); // Check new, reversed array
alert( "1st array:\n" + arr.join("\n") ); // Confirm no change in original
Tip: use the Array.slice() method (with zero as argument) to copy an entire array into another.
$arr = array( 'I', 'learn', 'PHP' );
// Modify the original array by assigning to it the function result:
$arr = array_reverse( $arr );
print_r( $arr ); // Array ( [0] => PHP [1] => learn [2] => I )
Sister method: sort() returns a case-sensitively, alpha-numerically sorted copy of another array.