![]() |
How to code a PHP sequence array. Help. Been googling, and I haven't found how to do an array that goes in sequence. Found how to do a random one. Code: // Create the array $links = array(); // Populare the array $links[0] = "http://www.site.com/ads1.php"; $links[1] = "http://www.site.com/ads2.php"; $links[2] = "http://www.site.com/ads3.php"; // Count links $num = count($links); // Randomize order $random = rand(0, $num-1); // Print random link echo $links[$random];I imagine this is fairly simple? Could someone show me or direct me to a website explaining? Thanks. |
Re: How to code a PHP sequence array. Help. Well the biggest problem will be the array for all users, they are controlled by a per page load basis. If you held it in a database then loaded it, going at random or some 50/50 chance would be easy. To populate an array like you ask all you need to do is $links[] = 'site1'; $links[] = 'site2'; this will add it to the end of the array, in the order you are looking for. Ok just to elaborate a little array pushing is used in many languages, you can do the same with the array_push function http://php.net/manual/en/function.array-push.php array_push($links,"site url"); but it use to be faster to do the way I mentioned above, I haven't tested it in a long time tho. |
Re: How to code a PHP sequence array. Help. Then you would do a count check $arr_size = count($links); if($user_click_count > ($arr_size - 1)) { $user_click_count = 0; //reset to 0 since we were at the end } |
Re: How to code a PHP sequence array. Help. I wrote a simple php script a while back that rotates between 10 different links in sequence. You could easily modify it to use how every many links you want... http://www.warriorforum.com/programm...ml#post2968668 |
Re: How to code a PHP sequence array. Help. Thanks guys! Going with Brandon's method. Testing it, seems like it'll work out great. |
| All times are GMT -6. The time now is 05:50 PM. |