Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Senior Coder
    Join Date
    May 2006
    Posts
    1,683
    Thanks
    28
    Thanked 4 Times in 4 Posts

    How do I select a random array element ?

    I would like to take a list of phrases and
    pick one out at random.

    PHP Code:
    $keywords = array( keyword one,keyword phrase two,and another,one,maybe one,more as well
    Maybe I need to write:

    PHP Code:
    $keywords = array( 'keyword one','keyword phrase two','and another','one','maybe one','more as well'
    How would I randomly pick one of these ?
    If you want to attract and keep more clients, then offer great customer support.

    Support-Focus.com. automates the process and gives you a trust seal to place on your website.
    I recommend that you at least take the 30 day free trial.

  • #2
    Regular Coder
    Join Date
    Oct 2004
    Posts
    168
    Thanks
    0
    Thanked 5 Times in 5 Posts
    PHP Code:
    $keywords = array( 'keyword one','keyword phrase two','and another','one','maybe one','more as well');

    shuffle($keywords);

    echo 
    $keywords[0]; 

  • #3
    Senior Coder
    Join Date
    May 2006
    Posts
    1,683
    Thanks
    28
    Thanked 4 Times in 4 Posts
    Oh - that's easy then

    Thanks
    If you want to attract and keep more clients, then offer great customer support.

    Support-Focus.com. automates the process and gives you a trust seal to place on your website.
    I recommend that you at least take the 30 day free trial.

  • #4
    Regular Coder
    Join Date
    Oct 2004
    Posts
    168
    Thanks
    0
    Thanked 5 Times in 5 Posts
    np, PHP has a function for everything - why reinvent the wheel ;-)


  •  

    Posting Permissions

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