Results 1 to 3 of 3
  1. #1
    Join Date
    Oct 2007
    Posts
    824
    Tokens
    71

    Latest Awards:

    Default [PHP] Question: Selecting Data from Array Randomly

    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.
    Vouches
    [x][x]

  2. #2
    Join Date
    Nov 2007
    Posts
    1,253
    Tokens
    150

    Latest Awards:

    Default

    This is if you have arrays like $blah['1'];

    PHP Code:

    $arrayC 
    count$array );
    $arrayC $arrayC 1;
    $arrayR rand0$arrayC );

    echo 
    $array["$arrayR"]; 
    Should work, sorry if not

    oorrrrr caleb suggested : http://uk.php.net/array_rand on msn didn't know that existed, silly me
    Last edited by Source; 22-02-2009 at 07:32 PM.


    www.fragme.co = a project.

  3. #3
    Join Date
    Oct 2007
    Posts
    824
    Tokens
    71

    Latest Awards:

    Default

    Exactly what I needed. Thanks.
    Vouches
    [x][x]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •