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

PHP explains how to use two array sorting functions_PHP tutorial

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-07-13 17:40:42
Original
1274 people have browsed it

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($...
source:php.cn
Statement of this Website
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
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template