0

我有两个文件 file4.php 和 file1.php

使用INCLUDE我如何将它们放在一个比例中,如果 file4.php 出现 4 次,那么 file1.php 应该出现 1 次,比例为 4:1。最佳实践是什么?

<?php 
  {
    include("file4.php");

} else {

    include("file1.php");
  }
?>
4

2 回答 2

7

这将显示两个页面之一,随着时间的推移,文件 4 的比例为 4:1。http://en.wikipedia.org/wiki/Law_of_large_numbers

$randInt = rand (1, 5);

if ($randInt > 1) include("file4.php");
else include("file1.php");
于 2012-04-16T21:17:34.980 回答
-2

文件4.php:

$GLOBALS['counter']++;

文件1.php:

$GLOBALS['counter']++;

主文件:

if ($GLOBALS['counter'] % 5 == 0) {
    include('file1.php');
} else {
    include('file4.php');
}

但是然后坐下来想知道为什么你需要这种东西。

于 2012-04-16T21:18:50.083 回答