根据随机顺序更改php页面上的swf文件


Change swf files on php page based on random order

我有4个flash文件,需要在打开php页面时显示。我们不希望页面每次都以相同的动画开始,所以我需要一个php脚本来旋转它们。我想每次打开页面时都把数字1-4打乱,并以此为基础显示swf。因此,如果混洗中的第一个数字是4,则显示swf4。我已经弄清楚了,但我如何在大约1分钟后根据shuffle数组中的顺序更改swf?

$values = range(1, 4);
shuffle($values);
foreach ($values as $value) {
$val[] = $value;
}
echo $val[0] . '<br>';
echo $val[1] . '<br>';
echo $val[2] . '<br>';
echo $val[3] . '<br>';

然后说数组$val[]=4,2,1,3,并且每个swf动画都是1分钟长,我需要显示swf4 1分钟,然后显示swf2 1分钟,再显示swf1 1分钟,等等。

这就是我最终所做的:

首先创建一个shuffle函数:

<script type="text/javascript">
Array.prototype.shuffle = function() {
    var input = this;
    for (var i = input.length-1; i >=0; i--) {
        var randomIndex = Math.floor(Math.random()*(i+1));
        var itemAtIndex = input[randomIndex];
        input[randomIndex] = input[i];
        input[i] = itemAtIndex;
    }
    return input;
}
</script>  

然后创建阵列并对其进行洗牌

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<script type="text/javascript">
var tempArray = [ 1, 2, 3, 4 ]
tempArray.shuffle();

//when the document is loaded display the first flash in the array
$( document ).ready(function() {
$.ajax( "flash-" + tempArray[0] + ".php" )
.done(function(res) {
        document.getElementById("swfdiv").innerHTML = res;
    })
});
//the function to display the second flash
function myFunction1() {
    //alert (tempArray[1]);
    $.ajax( "flash-" + tempArray[1] + ".php" )
    .done(function(res) {
        document.getElementById("swfdiv").innerHTML = res;
    })
}
//the function to display the thirdflash
function myFunction2() {
    //alert (tempArray[2]);
    $.ajax( "flash-" + tempArray[2] + ".php" )
    .done(function(res) {
        document.getElementById("swfdiv").innerHTML = res;
    })
}
//the function to display the fourth flash
function myFunction3() {
    //alert (tempArray[1]);
    $.ajax( "flash-" + tempArray[3] + ".php" )
    .done(function(res) {
        document.getElementById("swfdiv").innerHTML = res;
    })
}
//let the function for the second flash execute after 15 sec
setTimeout(myFunction1, 15000);
//let the function for the second flash execute after 30 sec
setTimeout(myFunction2, 30000);
//let the function for the second flash execute after 45 sec
setTimeout(myFunction3, 60000);
</script>