Skip to content

Instantly share code, notes, and snippets.

@mikestratton
Created May 9, 2015 04:38
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 mikestratton/87da42457621f7d397ac to your computer and use it in GitHub Desktop.
Save mikestratton/87da42457621f7d397ac to your computer and use it in GitHub Desktop.
Method: array_reverse — Return an array with elements in reverse order
<?php
// using method array_reverse
echo "Enter 5 elements:";
for($i = 0 ; $i<5;$i++)
{
$arr[$i]=trim(fgets(STDIN));
}
echo "\nYour input: \n";
foreach ($arr as $value1){
print_r($value1);
echo "\n";
}
echo "\nPreserved Array: \n";
$preserved = array_reverse($arr, true);
foreach ($preserved as $value2){
print_r($value2);
echo "\n";
}
echo "\nReversed Array: \n";
$reversed = array_reverse($arr);
foreach ($reversed as $value3){
print_r($value3);
echo "\n";
}
exit;
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment