How do I repeat a random number on a page ?

Discussion in 'PHP' started by Amilo, Sep 8, 2006.

  1. #1
    On a page I have a random number by using:

    echo rand(5, 10);

    I have a book on php that talks about random numbers but does not tell me how I can show the number generated on 2 more occasions elswere on the page.

    So whatever number is chosen in the 5, 10 statement I want to show the result again further down the page(the same number).
     
    Amilo, Sep 8, 2006 IP
  2. wmtips

    wmtips Well-Known Member

    Messages:
    601
    Likes Received:
    70
    Best Answers:
    1
    Trophy Points:
    150
    #2
    
    $num = rand(5, 10);
    echo $num;
    
    ...
    
    echo $num;
    
    ...
    
    echo $num;
    
    
    PHP:
     
    wmtips, Sep 8, 2006 IP
  3. Amilo

    Amilo Peon

    Messages:
    624
    Likes Received:
    18
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thank you for that.

    I thought it may include the echo statement.

    I also thought I would need to give it some sort of tag like $num;

    Good thing for me is I am starting to see what I need to do before asking now rather than posting in blind hope.
     
    Amilo, Sep 8, 2006 IP
  4. thedark

    thedark Well-Known Member

    Messages:
    1,346
    Likes Received:
    43
    Best Answers:
    0
    Trophy Points:
    168
    Digital Goods:
    1
    #4
    You must start to think like a programmer. :)
     
    thedark, Sep 8, 2006 IP