Page 1 of 1

Function Function whats my Function.

Posted: Fri Jan 09, 2009 12:45 pm
by Todlerone
Hello everyone and Happy New Year. Thank-you in advance for any help. I'm trying to tweak the code (original code works great) for my baseball league web site. I originally used alot of includes to process my MySql DB scores into a dynamic standings. I'm trying to convert them into functions. All I need to do in the function is to take some passed values from a Foreach loop and populate several arrays inside the function, then when the foreach loop is ended do some evaluation on the arrays. I don't need any Returned values from the function, merely to populate from inside and have access to the arrays outside of the function. Here's what I have come up with.....will it work?

$vis and $home are shortened team name variables like "ACE, HIT, COU..." and vis1 and home1 are the game one scores like" 05, 10..."

$vis and $home are the associative array keys for the $standings array. Originally I made a copy of my main schedule and converted all team names to numbers so that I could use them as numeral indexing for the arrays. Just want to eliminate that step and use the original schedule.

I want to use functions alot more, just need to understand a couple issues I have with them. Like I had said, the "includes" worked perfectly....I want to use functions instead ( I believe it is faster and more of the proper way...correct??)

Code: Select all

function game1($vis, $home, vis1, home1)
    {
       global $outcome, $overall, $standings;
   $standings=array();
 $outcome=array();
    $overall=array();
 
    
    $v=sizeof($outcome['$vis']);        //used for  the visitor team streak
    $h=sizeof($outcome['$home']);        //used for  the home team streak
    $standings['$vis'][1]+=1;            //game_vis games played+1 (game1)
    $standings['$home'][1]+=1;              //game_home games played+1 (game 1)
    $standings['$vis'][6]+=vis1;    //game_vis games runs for (game1)
    $standings['$home'][6]+=home1;    //game_home games runs for (game1)
    $standings['$vis'][7]+=home1;    //game_vis games runs against (game1)
    $standings['$home'][7]+=vis1;    //game_home games runs against (game1)
    if (vis1>home1){                //game1 loop (vis1>home1)
        $standings['$vis'][2]+=1;        //game_vis wins+1    (game1)
        $standings['$home'][3]+=1;        //game_home losses+1 (game1)
        $overall['$vis']['$home']+=1;    //head to head (game_vis win+1 against game_home)
        $outcome['$vis'][$v]="W";        //game_vis "win" outcome for game1
        $outcome['$home'][$h]="L";        //game_home "Loss" outcome for loser
    }elseif (vis1<home1){            //game1 vis1<home1
        $standings['$vis'][3]+=1;        //vis loses+1
        $standings['$home'][2]+=1;        //home wins+1
        $overall['$home']['$vis']+=1;    //head to head (home win-vis lose)+1
        $outcome['$vis'][$v]="L";        //game_vis1 loser
        $outcome['$home'][$h]="W";        //game_home1 winner    
    }else{                                //game1 vis1=home1
        $standings['$vis'][4]+=1;        //vis team ties+1
        $standings['$home'][4]+=1;        //home team ties+1
        $outcome['$vis'][$v]="T";        //game_vis tie
        $outcome['$home'][$h]="T";        //game_home tie
    }                                    //end game1 loop
    }  

Re: Function Function whats my Function.

Posted: Fri Jan 09, 2009 3:26 pm
by watson516
You could use a class instead no?

Re: Function Function whats my Function.

Posted: Fri Jan 09, 2009 10:16 pm
by Todlerone
Sorry, I'm a noob. Briefly what would that need? Thanx for the response watson.