php网页中对数组中的元素按随机顺序重新排列的教程

 2022-03-19    938  

实例说明:

<!DOCTYPE html>
<html>
<body>
<?php
$my_array = array("red","green","blue","yellow","purple");
shuffle($my_array);
print_r($my_array);
?>
<p>Refresh the page to see how shuffle() randomizes the order of the elements in the array.</p>
</body>
</html>

标签含义:

shuffle() 函数把数组中的元素按随机顺序重新排列。

该函数为数组中的元素分配新的键名,已存在的键名将被删除(参见下面的实例 1)。

源代码运行结果如下:

image.png

实例1

<!DOCTYPE html>
<html>
<body>

<?php
$my_array = array("a"=>"red","b"=>"green","c"=>"blue","d"=>"yellow","e"=>"purple");

shuffle($my_array);
print_r($my_array);
?>

<p>Refresh the page to see how shuffle() randomizes the order of the elements in the array.</p>

</body>
</html>

实例1源代码运行结果如下:

image.png


  •  标签:  
  • php
  •  

原文链接:https://77isp.com/post/767.html

=========================================

https://77isp.com/ 为 “云服务器技术网” 唯一官方服务平台,请勿相信其他任何渠道。