aebstract Posted September 9, 2008 Share Posted September 9, 2008 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! Quote Link to comment https://forums.phpfreaks.com/topic/123447-solved-exclude-numbers-from-rand/ Share on other sites More sharing options...
lanmonkey Posted September 9, 2008 Share Posted September 9, 2008 somthing like this? <?php $myarray = array(); for($i=0;$i<=5;$i++) { $myarray[] = 'filename'.$i.'.jpg'; } shuffle($myarray); foreach($myarray as $a) { echo $a.'<br />'; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/123447-solved-exclude-numbers-from-rand/#findComment-637597 Share on other sites More sharing options...
discomatt Posted September 9, 2008 Share Posted September 9, 2008 Same concept, fewer loops <?php $max = 5; $range = range(1,$max); shuffle( $range ); foreach ( $range as $id ) echo "picture$id.jpeg <br />"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/123447-solved-exclude-numbers-from-rand/#findComment-637630 Share on other sites More sharing options...
aebstract Posted September 9, 2008 Author Share Posted September 9, 2008 $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! Quote Link to comment https://forums.phpfreaks.com/topic/123447-solved-exclude-numbers-from-rand/#findComment-637665 Share on other sites More sharing options...
cheechm Posted September 9, 2008 Share Posted September 9, 2008 Can you give an example of an image name? It could be either ${'banner' . $id} or ${$banner . $i} Quote Link to comment https://forums.phpfreaks.com/topic/123447-solved-exclude-numbers-from-rand/#findComment-637698 Share on other sites More sharing options...
aebstract Posted September 9, 2008 Author Share Posted September 9, 2008 First one worked perfect, file name isn't important for that Thanks everyone Quote Link to comment https://forums.phpfreaks.com/topic/123447-solved-exclude-numbers-from-rand/#findComment-637718 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.