www.webdeveloper.com
Results 1 to 2 of 2

Thread: PHP Array Help

  1. #1
    Join Date
    Sep 2008
    Posts
    7

    PHP Array Help

    hello all.

    I'm currently developing a site for a baseball team, and I need some help with some PHP Arrays.

    What I'm trying to accomplish is basically get the value of a player's ratings in different areas(categories) of his game and use a formula to output his overall rating, according to their position:
    (LHP, RHP, C, 1B. 2B, 3B, SS, LF, CF, RF)

    Each player has a profile with his respected position, and also ratings in categories:
    (hitting, power, fielding, arm, speed, intangibles, body, velocity secP, outP, movement, command)

    First, I'll start with defining the position variable:
    PHP Code:
    <?php $pos get_field('position'); ?>

    Next, I'll define the variables for the categories and their values(which was input through the back end):


    PHP Code:

    <?php 
    $hitting 
    get_field('hitting'); 
    $power get_field('power');
    $fieldingget_field('fielding');
    $arm get_field('arm');
    $speed get_field('speed');
    $intangibles get_field('intangibles');
    $body get_field('body');

    $velocity get_field('velocity');
    $sec_pitches get_field('secondary_pitches');
    $out_pitch get_field('out_pitch');
    $movement get_field('movement');
    $command get_field('command');

    ?>




    Next, I have to write the array for each position's value, in their respected categories:

    PHP Code:
    <?php


                     
    // hitting       power   fielding     arm        speed  intangibles    body   velocity     secP    outP     movement   command
    $overallRatings_arr=array(
                            
            
    "LHP" => array(  0,        0,         0,          0,         0,          .1,        .1,        .3,        .15,     .15,        .1,         .1         ), 
                        
            
    "RHP" => array(     0,        0,         0,          0,         0,          .1,         .15,     .35,         .1,     .15,       .05,         .1         ), 
                        
            
    "C" => array(      .1,   .1,       .35,        .25,       .05,          .1,         .05,       0,          0,       0,         0,          0         ),
                    
            
    "1B" => array(     .3,    .3,        .1,         .1,       .05,         .05,          .1,       0,          0,       0,         0,          0         ),
                        
            
    "2B" => array(     .3,       .1,        .3,        .05,       .15,         .05,         .05,       0,          0,       0,         0,          0         ),
                        
            
    "3B" => array(     .3,   .25,        .1,        .15,       .05,         .05,          .1,       0,          0,       0,         0,          0         ),
                        
            
    "SS" => array(     .15,   .1,       .35,        .15,       .15,         .05,         .05,       0,          0,       0,         0,          0         ),
                    
            
    "LF" => array(     .3,   .25,        .1,         .1,           .1,         .05,          .1,       0,          0,       0,         0,          0         ),
                        
            
    "CF" => array(     .15,   .1,        .3,        .15,        .2,         .05,         .05,       0,          0,       0,         0,          0         ),
                
            
    "RF" => array(     .25,   .3,        .1,        .15,        .1,         .05,         .05,       0,          0,       0,         0,          0         )
                                
        );

    ?>
    Now, what I'm stuck on is basically getting the value of each position and creating the formula. I tried this, but to no avail.


    PHP Code:
    function overallRatings$pos) {
        global 
    $overallRatings_arr;
        
        
    $total 0;
        
        
    //echo "echoing the array " .$overallRatings_arr[0]."<br>";
        
        
    for ($i 0$i count($overallRatings_arr[$pos]); $i++) {
            
    //echo "rate value = ".$overallRatings_arr[$pos][$i]."<br>";
            
    if ($overallRatings_arr[$pos][$i] > 0) {
                
    $total += $values[$i] * $overallRatings_arr[$pos][$i];
            }
        }
        return 
    $total

    Can anyone help me with this?

    Thank you in advance!

  2. #2
    Join Date
    Oct 2008
    Location
    U.S.
    Posts
    726
    Where is $values defined?

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles