【发布时间】:2016-04-22 19:39:52
【问题描述】:
<?php
$urls = array (
"id=1.php",
"id=2.php",
"id=3.php" );
$random = (rand()%3);
header ("Location: ".$urls[$random]);
exit;
?>
我怀疑它可能会更好,尤其是因为每次添加新值时我都必须手动编辑 % 值。
【问题讨论】:
-
你为什么不直接使用
$random = mt_rand(0, count($urls) -1);? -
嗨,我的建议是不要保留动态页面,因为用户在重定向特定 url 时会感到困惑。
-
@CharlotteDunois 不应该是
$random = mt_rand(0, count($urls) - 1);吗? -
@Annshuk 嗯,上面的代码就是我的index.php。它应该将用户带到一个随机页面。
-
我会试试的,Charlotte 和 Saqib
标签: php arrays url math random