how to use php generate 5 numbers

Discussion in 'PHP' started by digitalspace, Apr 2, 2008.

  1. #1
    how to use php generate 5 numbers one time, the number should between 1 to30?
     
    digitalspace, Apr 2, 2008 IP
  2. mulari

    mulari Peon

    Messages:
    45
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #2
    not sure exactly what you need, what about this:

    $num will have 5 random numbers, you can also put it in an array to keep the 5 numbers to use later.
     
    mulari, Apr 2, 2008 IP
  3. NewTier

    NewTier Notable Member

    Messages:
    2,201
    Likes Received:
    196
    Best Answers:
    0
    Trophy Points:
    250
    #3
    Mulari is Right.

    Use this to generate 5 random numbers.

    change the number in red for your range.

    If you want the number to be echoed throughout the document use:

    <?=$num?>

    More Info: http://www.25x.us/?nwvuC3MKxs
     
    NewTier, Apr 2, 2008 IP
  4. ErectADirectory

    ErectADirectory Guest

    Messages:
    656
    Likes Received:
    65
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Or if you need to add them or do some other form of math later do this

    
    for ($i = 0; $i < 5; $i++)
    {
    $num[$i] = rand(1,30);
    }
    
    echo $num[0] ;
    echo $num[1] ;
    echo $num[2] ;
    echo $num[3] ;
    echo $num[4] . "<br><br>" ;
    echo $num[0] + $num[1] + $num[2] + $num[3] + $num[4]  ;
    
    PHP:
    It's nice sometimes having them in variables that you can use throughout a program
     
    ErectADirectory, Apr 2, 2008 IP
  5. digitalspace

    digitalspace Banned

    Messages:
    347
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    many thanks you all.
     
    digitalspace, Apr 3, 2008 IP