If I have an array and I want to select a random value from it would I be able to just do
rand($array);
Or what.
Edit by Robbie! (Forum Moderator) - Moved to Coding Help, please post in the correct section next time, thanks!

If I have an array and I want to select a random value from it would I be able to just do
rand($array);
Or what.
Edit by Robbie! (Forum Moderator) - Moved to Coding Help, please post in the correct section next time, thanks!
Last edited by Robbie; 22-02-2009 at 07:31 PM.
This is if you have arrays like $blah['1'];
Should work, sorry if notPHP Code:
$arrayC = count( $array );
$arrayC = $arrayC - 1;
$arrayR = rand( 0, $arrayC );
echo $array["$arrayR"];
oorrrrr caleb suggested : http://uk.php.net/array_rand on msndidn't know that existed, silly me
Last edited by Source; 22-02-2009 at 07:32 PM.
Want to hide these adverts? Register an account for free!