Average Numbers

Discussion in 'PHP' started by Silver89, Feb 27, 2009.

  1. #1
    Hey,

    If in php I'm returning a loop of numbers say about 500,

    How could I show the number that appears the most and the number that appears least within the sequence of these numbers?

    Also if there's more than 1 appears the least times then show both.

    Thanks for your help!
     
    Silver89, Feb 27, 2009 IP
  2. canishk

    canishk Peon

    Messages:
    46
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    can you tell me what exact you want, I didn't get any idea from this
     
    canishk, Feb 27, 2009 IP
  3. Silver89

    Silver89 Notable Member

    Messages:
    2,243
    Likes Received:
    72
    Best Answers:
    0
    Trophy Points:
    205
    #3
    Example with the following number sequence:

    1, 2, 2, 2, 4, 5, 5, 5, 5, 6, 6, 6, 7, 8, 8, 9, 9 ,9 ,9

    Lowest Appearing numbers
    1, 7

    Highest Appearing Numbers
    9
     
    Silver89, Feb 27, 2009 IP
  4. Barti1987

    Barti1987 Well-Known Member

    Messages:
    2,703
    Likes Received:
    115
    Best Answers:
    0
    Trophy Points:
    185
    #4
    My first guess would be to use a counter:

    $numberarray = array("0" -> "0", "1" => "1"); // etc..

    Increase each one when looping:

    numberarray[$loopnumbers][0]++;

    Then just arsort and take it from there.

    Peace,
     
    Barti1987, Feb 27, 2009 IP