Home  >  Article  >  Backend Development  >  lol re-random PHP reverse sorting and random sorting code

lol re-random PHP reverse sorting and random sorting code

WBOY
WBOYOriginal
2016-07-29 08:43:111411browse

Introduction to array_reverse() function and shuffle() function
array_reverse()
array array_reverse(array)array_reverse() function passes in an array as a parameter and returns an array with the same value as the passed parameter but in the opposite order.

Copy code The code is as follows:


$a = array(1,2,3,4,5);
$a = array_reverse($a);
for ($i =0; $iecho $a[$i]." ";
?>


The result is:
5 4 3 2 1
shuffle()
bool shuffle(array) The shuffle function randomly sorts the incoming array and returns TRUE if successful, otherwise it returns FALSE.

Copy code The code is as follows:


$a = array(1,2,3,4,5);
shuffle($a);
for ($i=0; $iecho $a[$i]." ";
shuffle($a);
echo "
";
for ($i= 0; $iecho $a[$i]." ";
?>


Results returned by two calls:
4 1 2 5 3
1 5 2 4 3

The above introduces the PHP reverse sorting and random sorting code of lol re-randomization, including the content of lol re-randomization. I hope it will be helpful to friends who are interested in PHP tutorials.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn