auto choose...

Discussion in 'PHP' started by Namuk, Mar 14, 2008.

  1. #1
    anyone know what are the function in php for auto choose value...

    i mean, when i click the button, computer will auto to print/choose the value....
    for example... i set the value that computer has to choose is A,B and C...

    so, when i click the button 'choose' for example, the computer will choose anyone of A, B, C..... (computer/machine will choose randomly)...

    please help me.....

    thanks....
     
    Namuk, Mar 14, 2008 IP
  2. mulari

    mulari Peon

    Messages:
    45
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #2
    here is small code example on how to use random:

    // setup an array of options
    $a = array('A', 'B', 'C');
    // get a random number between 0 and the number of items in the above array (-1)
    $i = rand(0, count($a)-1);
    // print the value
    echo $a[$i];
     
    mulari, Mar 14, 2008 IP
  3. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #3
    There's a function called array_rand(), which is made for this purpose. No need to use count() and rest one.
     
    nico_swd, Mar 15, 2008 IP