[英]Print PHP Shuffled Array To An Ordered List
I want to shuffle an array once a week and print it in an order list like this. 我想每周洗一次数组,并在这样的订单列表中打印。 So once a week this order would be different.
因此,每周一次此订单将有所不同。 I have the code for the array shuffle below, but having trouble printing the array to the ordered list - was going to figure out how to fire the script once a week after I got this part figured out.
我在下面有数组改组的代码,但是在将数组打印到有序列表时遇到了麻烦-我想弄清楚如何找出每周如何触发脚本的方法。
Here is the php code for the array shuffle: 这是数组随机播放的php代码:
<?php
$area_list = array(1 => "Northland", 2 => "North Linden", 3 => "South Linden", 4 => "Brice-Tussing", 5 => "Greater Hilltop", 6 => "Southside");
shuffle($area_list);
print_r($area_list);
?>
And this is my (bloated) code for the ordered list (ol): 这是我的有序列表(ol)的(blo肿的)代码:
<ol>
<li>
<div align="left">
<div align="left"><font color="#333333"><font size="2" >Northland</font></font></div>
</div>
</li>
<li>
<div align="left">
<div align="left"><font color="#333333"><font size="2" > North Linden</font></font></div>
</div>
</li>
<li>
<div align="left">
<div align="left"><font color="#333333"><font size="2" > South Linden</font></font></div>
</div>
</li>
<li>
<div align="left">
<div align="left"><font color="#333333"><font size="2" > Brice-Tussing</font></font></div>
</div>
</li>
<li>
<div align="left">
<div align="left"><font color="#333333"><font size="2" > Greater Hilltop</font></font></div>
</div>
</li>
<li>
<div align="left">
<div align="left"><font color="#333333"><font size="2" > Southside
</font></font></div>
</div>
</li>
</ol>
Columbus Ohio neighborhoods in case you were wondering. 俄亥俄州哥伦布(Columbus)社区,以防万一。 Thanks.
谢谢。
You can achieve this using foreach
: 您可以使用
foreach
实现此目的:
<?php
$area_list = array(1 => "Northland", 2 => "North Linden", 3 => "South Linden", 4 => "Brice-Tussing", 5 => "Greater Hilltop", 6 => "Southside");
shuffle($area_list);
echo "<ol>";
foreach($area_list as $area){
echo '<li><div align="left"><div align="left"><font color="#333333"><font size="2" >'.$area.'</font></font></div></div></li>';
}
echo "</ol>";
?>
All you need to do is output your starting tags (for the OL), and then loop through the $area_list array: 您需要做的就是输出您的开始标记(对于OL),然后遍历$ area_list数组:
<ol><?php foreach ($area_list as $al) {
?><li>
<div align="left">
<div align="left"><font color="#333333"><font size="2" ><?php echo $al;
?></font></font></div>
</div>
</li>
<?php
}
After that, output your closing "" and you should have what you want, or close to it. 之后,输出结束的“”,您应该拥有想要的东西,或者接近它。 Post back if you have further questions/problems.
如果您还有其他疑问/问题,请发回。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.