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
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!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.