1
我希望每次页面刷新或访问时,都要将此PHP变量的内容随机排列。随机顺序的可变内容
如
$test = 'a, b, c, d, e, f';
我想它随机最好的办法,例如
$test = 'c, b, d, f, a, e';
$test = 'd, e, c, a, f, b';
任何解决方案?
我希望每次页面刷新或访问时,都要将此PHP变量的内容随机排列。随机顺序的可变内容
如
$test = 'a, b, c, d, e, f';
我想它随机最好的办法,例如
$test = 'c, b, d, f, a, e';
$test = 'd, e, c, a, f, b';
任何解决方案?
$test = 'a, b, c, d, e, f';
$testArray = explode(', ',$test); //explode to array
shuffle($testArray); //shuffle it up
echo implode(', ', $testArray); //show the shuffledlyness
您是否尝试过自己什么? – 2012-04-11 20:09:02
http://us2.php.net/manual/en/function.rand.php – 2012-04-11 20:09:04
@Paul比'rand()'有更简单的方法。数组到'shuffle()'是我开始的地方... – 2012-04-11 20:10:34