Jump to content

[SOLVED] exclude numbers from rand() ?


aebstract

Recommended Posts

Not sure exactly how to approach what I am needing to do. I'm sure there are many different ways and I have a few ideas but nothing too solid, so.. Basically, Let's say I have 5 images. I want to display them in a random order. What I was going to do was assign a number to each one and grab a random number, and just take that number that was taken out of the random function and keep going until all the images are posted. Though, I bet there is an easier way to do this. Possibly somehow put all the images in an array and display the array in a random order? Any help as to what I can do and some guidance in the right direction would be awesome!

Link to comment
https://forums.phpfreaks.com/topic/123447-solved-exclude-numbers-from-rand/
Share on other sites

$max = 3;

$range = range(1,$max);
shuffle( $range );

foreach ( $range as $id ) {
$displaybanner .= "$banner$id";
}

This is doing exactly what I need it to do, except I'm having trouble getting my display to work right. Do you know how to add the word banner in front of the $id number and turn the whole thing in to a variable $banner# ?

Thanks!

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.