SitePoint Sponsor

User Tag List

Results 1 to 6 of 6

Thread: randomness!

  1. #1
    SitePoint Wizard
    Join Date
    Oct 2005
    Location
    London
    Posts
    1,678
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    randomness!

    hi,

    i want to display a different message to my users everytime they log in. I want it to be random. Ive thought that i could probably just create an array within my php code but im not too sure how to get it working so that a random message is pulled out everytime.

    Could anyone point me in the right direction?

  2. #2
    SitePoint Zealot mudda's Avatar
    Join Date
    Jul 2005
    Posts
    113
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You could probably incorporate the rand() function into it to pull out that number in the array. Just an idea. I've never really done one myself, but that seems like it would work. I know I've seen code someplace that does what you are asking, might just have to google it

  3. #3
    SitePoint Enthusiast
    Join Date
    Jan 2006
    Posts
    38
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Something like this.

    PHP Code:
    <?php

    $message
    [] = 'hi 0' ;
    $message[] = 'hi 1' ;
    $message[] = 'hi 2' ;
    $message[] = 'hi 3' ;
    $message[] = 'hi 4' ;

    echo 
    $message[rand(04)];
    ?>

  4. #4
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,578
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

  5. #5
    SitePoint Wizard
    Join Date
    Oct 2005
    Location
    London
    Posts
    1,678
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Great thanks guys!

  6. #6
    SitePoint Zealot
    Join Date
    Oct 2006
    Posts
    132
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    another option:

    PHP Code:
    shuffle($numbers);
    echo 
    $numbers[]0
    Al


Bookmarks

Posting Permissions

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