php对数组内元素进行随机调换的方法
(编辑:jimmy 日期: 2025/11/4 浏览:3 次 )
本文实例讲述了php对数组内元素进行随机调换的方法。分享给大家供大家参考。具体分析如下:
这是一个自定义的php数组元素随机调换的函数,php已经有一个内置的同样功能的函数shuffle($Array),这个代码权当参考
// I noticed that there is already a built-in function that
// does the same - so don't use mine ;-)
//
// --> shuffle($Array);
//
// http://de2.php.net/manual/de/function.shuffle.php
//
function RandomizeArray($array){
// error check:
$array = (!is_array($array)) "htmlcode">
/*
** Example:
*/
$test_array = array('why','dont','visit','www','jonas','john','de',':-)');
print implode(", ", $test_array);
print "\n";
print implode(", ", RandomizeArray($test_array));
/*
Example output:
why, dont, visit, www, jonas, john, de, :-)
www, de, jonas, john, visit, why, :-), dont
*/
希望本文所述对大家的php程序设计有所帮助。
下一篇:PHP SplObjectStorage使用实例