Home  >  Article  >  Backend Development  >  PHP explains how to use two array sorting functions_PHP tutorial

PHP explains how to use two array sorting functions_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 17:40:421173browse

array_reverse() Reverse sorting function
The 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.
$a = array(1,2,3,4,5);
$a = array_reverse($a);
for ($i=0; $i< ;count($a); $i)
echo $a[$i]." ";
?>
The result is:
5 4 3 2 1

shuffle() Random sorting code function
The function randomly sorts the incoming array and returns TRUE if successful, otherwise it returns FALSE.
$a = array(1,2,3,4,5);
shuffle($a);
for ($i=0; $iecho $a[$i]." ";
shuffle($a);
echo "
";
for ($i =0; $iecho $a[$i]." ";
?>
The result returned by two calls:
4 1 2 5 3
1 5 2 4 3

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/486189.htmlTechArticlearray_reverse() The reverse sorting function passes an array as a parameter and returns an array with the same value as the passed parameter but Array in reverse order. ?php $a = array(1,2,3,4,5); $a = array_reverse($...
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