Forum Moderators: coopster
[PHP]<?php
$title1[1] = "title1";
$title1[2] = "title2";
$title2[3] = "title3";
$title2[4] = "title4";
$img1[1] = "http://upload.wikimedia.org/wikipedia/commons/thumb/9/9f/BahnhofBludenz.JPG/120px-BahnhofBludenz.JPG";
$img1[2] = "http://upload.wikimedia.org/wikipedia/commons/thumb/3/3c/Korean_stew-Budae_jjigae-01.jpg/120px-Korean_stew-Budae_jjigae-01.jpg";
$img2[3] = "http://upload.wikimedia.org/wikipedia/commons/thumb/8/82/Basilica_Cistern%2C_Constantinople.jpg/120px-Basilica_Cistern%2C_Constantinople.jpg";
$img2[4] = "http://upload.wikimedia.org/wikipedia/commons/thumb/c/c4/A330-200F.jpg/120px-A330-200F.jpg";
if(isset($_COOKIE["array"]) && $_COOKIE["array"]=="two"){
setcookie("array", "one", time()+60*60*24*180);
$nbr1 = mt_rand(1, count($title2));
$nbr2 = mt_rand(1, count($img2));
}else{
setcookie("array", "two", time()+60*60*24*180);
$nbr1 = mt_rand(1, count($title1));
$nbr2 = mt_rand(3, count($img1));
}
$get1 = $title1[$nbr1];
$get2 = $img1[$nbr1];
echo "<img title='$get1' src='$get2' border='0'>";
?>
[/PHP]
These lines:
$get1 = $title1[$nbr1];
$get2 = $img1[$nbr1];
are always using $title1 and $img1 regardless of which branch of the if/else has executed. You should probably assign them in the if and else sections instead of below, so you know which arrays to use.
Also I think this line has problems:
$nbr2 = mt_rand(3, count($img1));
I think the 3 needs to be a 1.