Home > php教程 > php手册 > body text

PHP 讲解两种中数组排序函数使用方法

WBOY
Release: 2016-06-13 10:39:33
Original
1034 people have browsed it

array_reverse() 反向排序函数
函数传入参数为一数组,返回一个与传入参数值相同但顺序相反的数组。
$a = array(1,2,3,4,5);
$a = array_reverse($a);
for ($i=0; $iecho $a[$i]." ";
?>
结果为:
5 4 3 2 1

shuffle()  随机排序代码函数
函数对传入的数组进行随机排序,成功返回TRUE,否则返回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]." ";
?>
两次调用返回的结果:
4 1 2 5 3
1 5 2 4 3

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
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!