Hi, i have found the following code which works fine for two images but i am having problems adding adding more data to the array and displaying a third different image.
Please can someone tweak the code below to help me?
Kindest regards,
Brian
<?php
$images = array(0 => array ('portfolio/index.php','Qlink.gif'), 1 => array ('news.php','Qlink2.gif'), 2 => array ('fountain.php','Qlink3.gif'), 3 => array ('castle.php','Qlink4.gif'));
$imageone='';
$imagetwo='';
function create(){
$chosen = array();
global $imageone, $imagetwo;
$i='1';
while ($i <= 2){
$random = rand(0, 3);
if (!in_array($random, $chosen)){
array_push($chosen, $random);
$i++;
}
}
$imageone = $chosen['0'];
$imagetwo = $chosen['1'];
}
create();
?>
Then call it like this
<a href="<?php echo $images[$imageone][0]; ?>" title="link to page"><img src="default_image_folder/<?php echo $images[$imageone][1]; ?>" alt="random image and link" /></a>
Please can someone tweak the code below to help me?
Kindest regards,
Brian
<?php
$images = array(0 => array ('portfolio/index.php','Qlink.gif'), 1 => array ('news.php','Qlink2.gif'), 2 => array ('fountain.php','Qlink3.gif'), 3 => array ('castle.php','Qlink4.gif'));
$imageone='';
$imagetwo='';
function create(){
$chosen = array();
global $imageone, $imagetwo;
$i='1';
while ($i <= 2){
$random = rand(0, 3);
if (!in_array($random, $chosen)){
array_push($chosen, $random);
$i++;
}
}
$imageone = $chosen['0'];
$imagetwo = $chosen['1'];
}
create();
?>
Then call it like this
<a href="<?php echo $images[$imageone][0]; ?>" title="link to page"><img src="default_image_folder/<?php echo $images[$imageone][1]; ?>" alt="random image and link" /></a>