SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Zealot gregs's Avatar
    Join Date
    Aug 2002
    Posts
    161
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    A little ARRAY help, please

    PHP Code:
    <?php
     
    // Legend    Key - User - Year - Week - Game - Information about game
     
    $arrayPickem = array();
    $arrayPickem[0]['Adam'][2004][2][1]['home_team']='Jonesboro';
    $arrayPickem[0]['Adam'][2004][2][1]['guest_team']='Wynne';
    $arrayPickem[0]['Adam'][2005][1][1]['home_team']='Searcy';
    $arrayPickem[0]['Adam'][2005][1][1]['guest_team']='Wynne';
    $arrayPickem[1]['Fred'][2004][1][1]['home_team']='Wynne';
    $arrayPickem[1]['Fred'][2004][1][1]['guest_team']='Searcy';
    $arrayPickem[1]['Fred'][2004][1][2]['home_team']='New Madrid';
    $arrayPickem[1]['Fred'][2004][1][2]['guest_team']='Jonesboro';
    $arrayPickem[0]['Adam'][2004][2][2]['home_team']='Osceola';
    $arrayPickem[0]['Adam'][2004][2][2]['guest_team']='Forrest City';
    $newuser 'Robert';
    $year 2005;
    $week 1;
    $game 1;
    $guestteam 'Wynne';
    $hometeam 'Searcy';
     
    $arrayPickem[] = $newuser// How do I add this new user?
    // I am not even sure if I am going about this in the correct way
     
     
    echo "There are ".sizeof($arrayPickem)." Users in our database.</p>\n";
    foreach( 
    $arrayPickem as $arrKey=>$arrayUsers )
    {
    echo 
    '<b>'.$arrKey."</b><br />\n";
    foreach( 
    $arrayUsers as $arrUser=>$arrayYears )
    {
        echo 
    '<b>'.$arrUser."</b><br />\n";
        foreach( 
    $arrayYears as $arrYear=>$arrayWeeks )
        {
         echo 
    " ".$arrYear."<br />\n";
         foreach( 
    $arrayWeeks as $arrWeek=>$arrayGames )
         {
            echo 
    '    '.$arrWeek."<br />\n";
            foreach( 
    $arrayGames as $arrGame )
            {
             echo 
    '     '.$arrGame['guest_team']." at ".$arrGame['home_team']."<br />\n";
            }
         }
        }
    }
    echo 
    "<BR />\n";
    }
     
    print_r($arrayPickem);
    ?>
    Last edited by gregs; Jun 22, 2005 at 15:35.

  2. #2
    get into it! bigduke's Avatar
    Join Date
    May 2004
    Location
    Australia
    Posts
    847
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok try this first
    PHP Code:
    echo '<pre>';
    print_r($pickemArray);
    echo 
    '</pre>'
    And then report your result here.

  3. #3
    SitePoint Zealot gregs's Avatar
    Join Date
    Aug 2002
    Posts
    161
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    I still need a little help, please.
    I just know I am going to crawl under a rock once I see how simple this was!

  4. #4
    SitePoint Guru dbevfat's Avatar
    Join Date
    Dec 2004
    Location
    ljubljana, slovenia
    Posts
    684
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Why don't you do what bigduke told you to?

    And what is your question precisely?

  5. #5
    SitePoint Zealot gregs's Avatar
    Join Date
    Aug 2002
    Posts
    161
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    I did do what BigDuke said to do, and I can see it is not making the array correctly.

    PHP Code:
    $arrayPickem[0]['Adam'][2004][2][2]['guest_team']='Forrest City';
     
    $newuser 'Robert';
    $year 2005;
    $week 1;
    $game 1;
    $guestteam 'Wynne';
    $hometeam 'Searcy';
     
    $arrayPickem[] = $newuser// How do I add this new user, Robert, to arrayPickem like Adam? This doesnt work right!!! 
    </FONT>

  6. #6
    SitePoint Guru dbevfat's Avatar
    Join Date
    Dec 2004
    Location
    ljubljana, slovenia
    Posts
    684
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    His point was to show US the result

    Try this:
    PHP Code:
    function fill_user(&$array$index$name$year$week$game$team$team_name)
    {
      
    $array[$index][$name][$year][$week][$game][$team] = $team_name;
    }

    fill_user($arrayPickem2'Robert'200511'guest_team''Wynne');
    fill_user($arrayPickem2'Robert'200511'home_team''Searcy'); 


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
  •