![]() |
Showing random links with an array
Code:
<?phpProxy #1 Proxy #1 Proxy #1 Proxy #3 true enough, its random but i dont want dupliates, i need all random like: Proxy #6 Proxy #7 Proxy #9 Proxy #2 Proxy #3 What can i add to the code to get it without duplicates? |
PHP Code:
|
@ Enfernikus, the most regular and correct way of increasing or decreasing is $i++ and $i--.
PHP Code:
The best thing to do is to make it database driven, because then you can later add the URL which makes checking easier. Also, the mt_rand can be greatly increased in random numbers. Insert them all into an array (about 20 times, of course in the for loop) and then choose with the mt_rand again a number (key) out of that array, which resembles another number. For example, you'll get mt_rand 20 times, on key 19 you're going to get the number 8. So, if the next mt_rand (that finalizes the random) poops out the key 19, you'll get 8 as the random number. This would mean that you can make about 10000 keys in the array, all matching from 1 to the array size of your proxy array. In this case, 10000 different numbers from 0 to 10. Good luck! |
Quote:
If you're wanting another approach, copy the original array into a new temporary variable. Then, shuffle it and array_slice however many you want. |
Yeah I know, but the method I use is faster and ++$i and $i++ look nearly identical - there are some drawbacks but I think it's worth the increase.
|
Yea Salathe is correct, there wont be any duplicates unless you introduce them into the array. Therefor this is probably the easiest way of doing it:
PHP Code:
|
Quote:
Slicing the array is also a good method, but I prefer my way. ;-) |
| All times are GMT. The time now is 01:44 PM. |
Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0