I know this is totally wrong, but its the closest i got to what i want. please help.

Discussion in 'PHP' started by Herpsy, Feb 2, 2012.

  1. #1
    
    $limit = 9;    
    $minNumber =1;   
     $maxNumber =9;   
     $numbers = array ();      
      for ( $x = 1; $x <= $limit; $x ++ ){       
     $numbers[$x] = rand($minNumber,$maxNumber);       
     foreach($numbers as $var=>$val){           
     $$var = $val;        }   
     echo $var . " = " . $val . "<br>";    }
    
    PHP:
    output:

    1 = 2
    2 = 1
    3 = 7
    4 = 9
    5 = 1
    6 = 2
    7 = 7
    8 = 3
    9 = 3
    99

    99?? WTF can you explain that to a rook?

    what i want is thisi know the foreach should not be in the for statement. but i am lost. noob here

    1 = 2
    2 = 1
    3 = 7
    4 = 9
    5 = 1
    6 = 2
    7 = 7
    8 = 3
    9 = 3

    ps wtf formatting!!!!

     
    Herpsy, Feb 2, 2012 IP
  2. Herpsy

    Herpsy Member

    Messages:
    40
    Likes Received:
    3
    Best Answers:
    1
    Trophy Points:
    43
    #2
    Fixed. Thanks anyway


    
    
        $limit = 9;    
    $minNumber =1;   
     $maxNumber =9;    
    $numbers = array ();       
     for ( $x = 1; $x <= $limit; $x ++ ){      
      $string = 'img'.$x;        
    $$string = rand($minNumber,$maxNumber);          
      }
    
        for($x = 1; $x <= $limit; $x ++){     
       $string = 'img'.$x;            
    //echo $x . " = " . $$string . "<br>";   
     }
    
    PHP:
     
    Herpsy, Feb 2, 2012 IP