PHP 反向排序和随机排序代码_PHP教程

WBOY
Libérer: 2016-07-21 15:36:38
original
1318 Les gens l'ont consulté

array_reverse()函数与shuffle()函数介绍

array_reverse()
array array_reverse(array)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()
bool shuffle(array)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/322125.htmlTechArticlearray_reverse()函数与shuffle()函数介绍 array_reverse() array array_reverse(array)array_reverse()函数传入参数为一数组,返回一个与传入参数值相同但顺序相...
source:php.cn
Déclaration de ce site Web
Le contenu de cet article est volontairement contribué par les internautes et les droits d'auteur appartiennent à l'auteur original. Ce site n'assume aucune responsabilité légale correspondante. Si vous trouvez un contenu suspecté de plagiat ou de contrefaçon, veuillez contacter admin@php.cn
Tutoriels populaires
Plus>
Derniers téléchargements
Plus>
effets Web
Code source du site Web
Matériel du site Web
Modèle frontal
À propos de nous Clause de non-responsabilité Sitemap
Site Web PHP chinois:Formation PHP en ligne sur le bien-être public,Aidez les apprenants PHP à grandir rapidement!