Created
May 9, 2015 04:38
-
-
Save mikestratton/87da42457621f7d397ac to your computer and use it in GitHub Desktop.
Method: array_reverse — Return an array with elements in reverse order
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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