Heim  >  Artikel  >  Backend-Entwicklung  >  PHP 讲解两种中数组排序函数使用方法_PHP教程

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

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

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

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/486189.htmlTechArticlearray_reverse() 反向排序函数 函数传入参数为一数组,返回一个与传入参数值相同但顺序相反的数组。 ?php $a = array(1,2,3,4,5); $a = array_reverse($...
Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn