我在网上发现了这个精彩的片段。 它在页面刷新时随机显示一个新的证明,并且想知道如何以升序而不是随机显示数组?我如何排序数组而不是随机
$target = sort(0, $num-1);
^这是我尝试
<?php
/*
--------------------------------------------
Random Testimonial Generator Created by:
Ryan McCormick
Ntech Communications
Website: http://www.ntechcomm.com/
Blog: http://www.ntechcomm.com/blog/
Twitter: @ntechcomm
--------------------------------------------
*/
//Start Array
$testimonials = array();
$testimonials[0] = "Testimonial 1";
$testimonials[1] = "Testimonial 2";
$testimonials[2] = "Testimonial 3";
$testimonials[3] = "Testimonial 4";
//Automate script by counting all testimonials
$num = count($testimonials);
//randomize target testimonial
$target = rand(0, $num-1);
/*
To display testimonials on site
--------------------------------------------
place the following code in the
display area:
<?php echo $testimonials[$target]; ?>
--------------------------------------------
Use a PHP include to use this code on your
target page.
*/
?>
输出的告别赛在页面:
<?php echo $testimonials[$target]; ?>
澄清:
我张贴显示一个告别赛随机代码刷新页面。我希望它保持此功能,并一次只显示一个,但我希望它们按照它们添加的顺序显示。
在这种情况下不要使用'rand()'? – 2015-02-24 16:21:09