Hi all...
I am new to the forum and new to PHP, so be gentle. I have been searching the web for this all day so forgive me if I have missed a post that answers my question.
I want to display 4 images (but with possibility of more in future) on a page which are randomly selected from a number of possible images. at the moment I have each possible image as a list in an array, and have found it simple enough to generate the 4 images randomly. The problem I am having is that I don't want the same image to appear more than once, and am having trouble doing this.
As I said, I am new to PHP so I have a lot to learn, but I have built a (fairly basic, admitedly) application in AppleScript on a mac, so I am familiar with many of the basic concepts behind programming, and I could do what I want in AppleScript, but am having trouble translating it to PHP, plus it's been a while since I did that anyway.
I'm sure there must be a simple answer, but I can't find it so any suggestions would be greatly appreciated.
Here is the script I have so far: (any tips to clean it up also welcome!)
<?php
$file_array = array
(
'93.jpg',
'96.jpg',
'900.jpg',
'962.jpg',
'93.jpg',
'93.jpg',
'aerobadge.jpg',
'aeroX1.jpg',
'aeroX2.jpg',
'aeroX3.jpg',
);
$total = count($file_array);
$random = (mt_rand()%$total);
$file1 = "$file_array[$random]";
$file_array= array_values($file_array);
$random = (mt_rand()%$total);
$file2 = "$file_array[$random]";
$file_array= array_values($file_array);
$random = (mt_rand()%$total);
$file3 = "$file_array[$random]";
$file_array= array_values($file_array);
$random = (mt_rand()%$total);
$file4 = "$file_array[$random]";
Now I tried to get what I want using if statements or repeat loops but one got very confusing and the other froze up the CPU and didn't really work anyway!
then I figured if I move through the images one by one, removing it from the array as it is used, that would solve it, but I couldn't get it to work....
any help appreciated,
arumdevil