10-23-2008, 10:56 PM
|
#3 (permalink)
|
|
The Frequenter
Join Date: Nov 2007
Location: Netherlands
Posts: 460
Thanks: 49
|
@ Enfernikus, the most regular and correct way of increasing or decreasing is $i++ and $i--.
PHP Code:
<?php
error_reporting( E_ALL | E_STRICT ); ob_start("ob_gzhandler");
$proxyArray = array("proxy.address.com/proxy1", "proxy.address.com/proxy2", "proxy.address.com/proxy3", "proxy.address.com/proxy4", "proxy.address.com/proxy5", "proxy.address.com/proxy6", "proxy.address.com/proxy7", "proxy.address.com/proxy8", "proxy.address.com/proxy9", "proxy.address.com/proxy10"); $proxyArraySize = (sizeof($proxyArray) - 1); shuffle($proxyArray); $proxiesToDisplay = 5; $displayArray = array(); for($i = 0; $i < $proxiesToDisplay; $i++) { $randomProxyNumber = mt_rand(0, $proxyArraySize); if (!in_array($proxyArray[$randomProxyNumber], $displayArray)) { array_push($displayArray, $proxyArray[$randomProxyNumber]); } else { $i--; } } foreach($displayArray as $displayProxy) { echo $displayProxy . '<br>' . "\n"; }
Naturally, you can apply the same with the function in_array again. I only check for the values. Since you've got a unique value, you should check for both. Assuming they don't match up.
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!
__________________
"Life is a bitch, take that bitch on a ride"
|
|
|