Help: Simple variable arranging

Discussion in 'PHP' started by Skillman13, Dec 28, 2009.

  1. #1
    Im just playing with php and i wanted to make a fake lottery generator -picks 6 random numbers, which works ok...

    But i want it to display all six in order, how would I do that
    For example, $lotnumber1 = 11, $lotnumber1 = 39, $lotnumber1 = 19, $lotnumber1 = 22, $lotnumber1 = 4, $lotnumber1 = 42,

    I don't want it display 11,39,19,22,4,42 when i echo it out...

    I want it to display 4,11,19,22,39,42..

    How can I do this?

    Thanks,

    James
     
    Skillman13, Dec 28, 2009 IP
  2. MartiCode

    MartiCode Peon

    Messages:
    31
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    implode(',' asort(explode(',' $list)))
     
    MartiCode, Dec 28, 2009 IP
  3. Skillman13

    Skillman13 Peon

    Messages:
    229
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Ok thanks,
     
    Skillman13, Dec 28, 2009 IP
  4. JAY6390

    JAY6390 Peon

    Messages:
    918
    Likes Received:
    31
    Best Answers:
    0
    Trophy Points:
    0
    #4
    $nums = range(1,49);
    $draws = 6;
    $balls = array();
    
    $draw = array_rand($nums, $draws);
    if(!is_array($draw)) {
        $draw[0] = $draw;
    }
    
    foreach($draw as $k => $v) {
        $balls[] = $nums[$v];
        unset($nums[$v]);
    }
    echo '<pre>'.print_r($balls, true).'</pre>';
    PHP:
     
    JAY6390, Dec 28, 2009 IP