SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast geeOff's Avatar
    Join Date
    Jul 2001
    Location
    Atlanta, GA 30328
    Posts
    72
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    looping thru multiple arrays ??

    hey guys --

    i think this is a simple problem, but i am pulling my hair out trying to get it to work. i have 1 array & i am randomizing the contents in 7 different instances & then based on what is item ("$EQ1","$EQ2","$EQ3",etc.) chosen in any given instance, i set the same variables ($input1 = "2";$input2 = "2";$input3 = "2"; etc.) for each unique array item. so instead of having to do this 7 times x, i was trying to make maybe a for loop that would assign the same variables no matter what number array was used...

    so far all my for ($i = 0; $i < 8; $i++) {// if the random item is X, assign vars 1-6} loops just keep breaking, trying to make all the $rand_keys1[0]] == "$EQ1") into $rand_keys[$i][0]] == "$EQ1"). then i tried making my rand_keys1, rand_keys2, etc.. into rand_keys[], but no dice. any ideas ??

    PHP Code:
        srand ((double) microtime() * 10000000);
    // random horsepower generator
        
    $randomEqs = array ("$EQ1","$EQ2","$EQ3","$EQ4","$EQ5","$EQ6","$EQ7");
        
    $rand_keys1 array_rand ($randomEqs2);
        
    $rand_keys2 array_rand ($randomEqs2);
        
    $rand_keys5 array_rand ($randomEqs2);
        
    $rand_keys6 array_rand ($randomEqs2);
        
    $rand_keys7 array_rand ($randomEqs2);
    // 1 equation key pieces

    if ($randomEqs[$rand_keys1[0]] == "$EQ1"):
        
    $input1 "2";
        
    $input2 "2";
        
    $input3 "2";
        
    $input4 "5";
        
    $input5 "4";
        
    $input6 "2";
    endif;
    if (
    $randomEqs[$rand_keys1[0]] == "$EQ2"):
        
    $input1 "";
        
    $input2 "2";
        
    $input3 "4";
        
    $input4 "3";
        
    $input5 "2";
        
    $input6 "2";
    endif;
    if (
    $randomEqs[$rand_keys1[0]] == "$EQ3"):
        
    $input1 "2";
        
    $input2 "2";
        
    $input3 "6";
        
    $input4 "7";
        
    $input5 "4";
        
    $input6 "6";
    endif;
    if (
    $randomEqs[$rand_keys1[0]] == "$EQ4"):
        
    $input1 "";
        
    $input2 "";
        
    $input3 "4";
        
    $input4 "2";
        
    $input5 "";
        
    $input6 "2";
    endif;
    if (
    $randomEqs[$rand_keys1[0]] == "$EQ5"):
        
    $input1 "";
        
    $input2 "3";
        
    $input3 "8";
        
    $input4 "5";
        
    $input5 "3";
        
    $input6 "4";
    endif;
    if (
    $randomEqs[$rand_keys1[0]] == "$EQ6"):
        
    $input1 "2";
        
    $input2 "3";
        
    $input3 "6";
        
    $input4 "9";
        
    $input5 "6";
        
    $input6 "6";
    endif;
    if (
    $randomEqs[$rand_keys1[0]] == "$EQ7"):
        
    $input1 "2";
        
    $input2 "";
        
    $input3 "<font face=\"sl\">3</font>OH";
        
    $input4 "3";
        
    $input5 "2";
        
    $input6 "4";
    endif; 
    thx,
    Geoff

  2. #2
    SitePoint Enthusiast geeOff's Avatar
    Join Date
    Jul 2001
    Location
    Atlanta, GA 30328
    Posts
    72
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    whoops !!

    nevermind...i got it fixed. all i needed were (7) unique random items in this 1 page, so i was able to do it like so (actually 15 items to deal with). still pretty inefficient (i am a newbie), but works ok...then i just call $randomEqs[$rand_keys1[0]], $randomEqs[$rand_keys1[1]], etc.. and the $input1 - 6 vars / pieces wherever i need them.

    PHP Code:

    // seed with microseconds since last "whole" second
        
    srand ((double) microtime() * 10000000);
    // random horsepower generator
        
    $randomEqs = array ("$EQ1","$EQ2","$EQ3","$EQ4","$EQ5","$EQ6","$EQ7","$EQ8","$EQ9","$EQ10","$EQ11","$EQ12","$EQ13","$EQ14","$EQ15");
        
    $rand_keys1 array_rand ($randomEqs7);
    // 1 equation key pieces
    for ($i 0$i 7$i++): 
    if (
    $randomEqs[$rand_keys1[$i]] == "$EQ1"):
        
    $input1 "2";
        
    $input2 "2";
        
    $input3 "2";
        
    $input4 "5";
        
    $input5 "4";
        
    $input6 "2";
        else:
    endif;
    if (
    $randomEqs[$rand_keys1[$i]] == "$EQ2"):
        
    $input1 "";
        
    $input2 "2";
        
    $input3 "4";
        
    $input4 "3";
        
    $input5 "2";
        
    $input6 "2";
    endif;
    if (
    $randomEqs[$rand_keys1[$i]] == "$EQ3"):
        
    $input1 "2";
        
    $input2 "2";
        
    $input3 "6";
        
    $input4 "7";
        
    $input5 "4";
        
    $input6 "6";
    endif;
    if (
    $randomEqs[$rand_keys1[$i]] == "$EQ4"):
        
    $input1 "";
        
    $input2 "";
        
    $input3 "4";
        
    $input4 "2";
        
    $input5 "";
        
    $input6 "2";
    endif;
    if (
    $randomEqs[$rand_keys1[$i]] == "$EQ5"):
        
    $input1 "";
        
    $input2 "3";
        
    $input3 "8";
        
    $input4 "5";
        
    $input5 "3";
        
    $input6 "4";
    endif;
    if (
    $randomEqs[$rand_keys1[$i]] == "$EQ6"):
        
    $input1 "2";
        
    $input2 "3";
        
    $input3 "6";
        
    $input4 "9";
        
    $input5 "6";
        
    $input6 "6";
    endif;
    if (
    $randomEqs[$rand_keys1[$i]] == "$EQ7"):
        
    $input1 "2";
        
    $input2 "";
        
    $input3 "<font face=\"sl\">3</font>OH";
        
    $input4 "3";
        
    $input5 "2";
        
    $input6 "4";
    endif;
    if (
    $randomEqs[$rand_keys1[$i]] == "$EQ8"):
        
    $input1 "";
        
    $input2 "2";
        
    $input3 "<font face=\"sl\">5</font>OH";
        
    $input4 "3";
        
    $input5 "2";
        
    $input6 "3";
    endif;
    if (
    $randomEqs[$rand_keys1[$i]] == "$EQ9"):
        
    $input1 "2";
        
    $input2 "4";
        
    $input3 "10";
        
    $input4 "13";
        
    $input5 "8";
        
    $input6 "10";
    endif;
    if (
    $randomEqs[$rand_keys1[$i]] == "$EQ10"):
        
    $input1 "";
        
    $input2 "4";
        
    $input3 "8";
        
    $input4 "6";
        
    $input5 "4";
        
    $input6 "4";
    endif;
    if (
    $randomEqs[$rand_keys1[$i]] == "$EQ11"):
        
    $input1 "2";
        
    $input2 "4";
        
    $input3 "6";
        
    $input4 "11";
        
    $input5 "8";
        
    $input6 "6";
    endif;
    if (
    $randomEqs[$rand_keys1[$i]] == "$EQ12"):
        
    $input1 "";
        
    $input2 "5";
        
    $input3 "12";
        
    $input4 "8";
        
    $input5 "5";
        
    $input6 "6";
    endif;
    if (
    $randomEqs[$rand_keys1[$i]] == "$EQ13"):
        
    $input1 "2";
        
    $input2 "5";
        
    $input3 "10";
        
    $input4 "15";
        
    $input5 "10";
        
    $input6 "10";
    endif;
    if (
    $randomEqs[$rand_keys1[$i]] == "$EQ14"):
        
    $input1 "";
        
    $input2 "5";
        
    $input3 "8";
        
    $input4 "7";
        
    $input5 "5";
        
    $input6 "4";
    endif;
    if (
    $randomEqs[$rand_keys1[$i]] == "$EQ15"):
        
    $input1 "2";
        
    $input2 "6";
        
    $input3 "6";
        
    $input4 "15";
        
    $input5 "12";
        
    $input6 "6";
    endif;
    endfor; 
    Last edited by geeOff; Jul 26, 2001 at 14:28.

  3. #3
    SitePoint Enthusiast geeOff's Avatar
    Join Date
    Jul 2001
    Location
    Atlanta, GA 30328
    Posts
    72
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    test again

    [ ... ]


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •