PDA

View Full Version : PHP Randomly Picking a String


majik92
02-23-2007, 09:41 AM
Suppose I have four strings in a PHP file:


$locationOne = "http://www.example.com/file.wma";
$locationTwo = "http://www.example2.com/file.wma";
$locationThree = "http://www.example3.com/file.wma";
$locationFour = "http://www.example4.com/file.wma";


How do I make the PHP script randomly choose which one to send back to the app?

TJ_Tigger
02-23-2007, 09:50 AM
Put them in an array and generate a random number from one to the total number of entries in the array and then extract and return that one item.

I don't have the code but w3schools has a lot of good information on PHP.

Tigg

TJ_Tigger
02-23-2007, 09:55 AM
It is even easier with this array_rand() function (http://www.w3schools.com/php/func_array_rand.asp)

majik92
02-23-2007, 06:14 PM
thank u, tj