WEB PHP Crew - Quick Help

Discussion in 'OT Technology' started by tehganj, Mar 4, 2008.

  1. tehganj

    tehganj oh, hi.

    Joined:
    Dec 3, 2007
    Messages:
    3,123
    Likes Received:
    0
    Location:
    LA, Cali
    Hey guys... I'm trying to cook up this quick parsing/average script but for some reason I'm stuck... Here's what I'm trying to do.

    I have a number (like 3.4) and a domain (domain.com) both are in arrays (using preg_match_all) and I'm trying to find all domains that are alike and add the numbers then get the average between them and echo the avg number + the domain the avg number belongs to. I've tried using a foreach but it's going thru each domain even if there's doubles which I knew would happen but hoped it didn't.

    Example

    5.3949 - domain.com
    0.948 - domain2.com
    1.42 - domain.com
    6.902 - domain2.com

    I want to get the avg number for both domains (domain.com and domain2.com) list on the left hand side and only echo the domain once.

    I'm just rambling on but it's been a long night... :o
     
  2. kingtoad

    kingtoad OT Supporter

    Joined:
    Sep 2, 2003
    Messages:
    55,923
    Likes Received:
    11
    Location:
    Los Angeles
    What algorithm are you using to detect how each domains are alike?
     
  3. Limp_Brisket

    Limp_Brisket New Member

    Joined:
    Jan 2, 2006
    Messages:
    48,422
    Likes Received:
    0
    Location:
    Utah
    i'm not sure what you're trying to do but it sounds like you would want to make a loop going through your other data and averaging it while using the domain as the key to keep the entries unique.

    so in each instance of the loop it'd be like:

    $myArray[$domain] = ($myArray[$domain] + $newNum) / 2;
     

Share This Page