Help: Comparing 4 php integer variables

Discussion in 'PHP' started by Skillman13, Nov 21, 2009.

  1. #1
    I have four variables...

    $killhousetries1 = 0
    $killhousetries2 = 1
    $killhousetries3 = 0
    $killhousetries4 = 0

    What code could I use to find out the biggest variable out of the 4? (which -this time, would be $killhousetries2)

    Please help,

    Thanks...

    James
     
    Skillman13, Nov 21, 2009 IP
  2. gabibeowulfx

    gabibeowulfx Active Member

    Messages:
    211
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    63
    #2
    Try this:

    echo max($killhousetries1, $killhousetries2, $killhousetries3, $killhousetries4 );
     
    gabibeowulfx, Nov 21, 2009 IP
  3. Skillman13

    Skillman13 Peon

    Messages:
    229
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Works, ok thanks.
     
    Skillman13, Nov 21, 2009 IP
  4. Skillman13

    Skillman13 Peon

    Messages:
    229
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Hmm, is there any way to say which variable itself is bigger? -not what number is the biggest?
     
    Skillman13, Nov 21, 2009 IP
  5. Skillman13

    Skillman13 Peon

    Messages:
    229
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    ? =/ anyone?
     
    Skillman13, Nov 22, 2009 IP
  6. Skillman13

    Skillman13 Peon

    Messages:
    229
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Anyone? =/
     
    Skillman13, Nov 26, 2009 IP
  7. markowe

    markowe Well-Known Member

    Messages:
    1,136
    Likes Received:
    26
    Best Answers:
    0
    Trophy Points:
    165
    #7
    I can't quite get my head round a full solution just this second, but just thinking aloud, why not store the variables and their values in an associative array, like array('killhousetries1' => $killhousetries1, 'killhousetries2' => $killhousetries2 etc.) and then sort them in order of size using array_multisort, and then extracting the key names back out to find the top one. That last bit might be unnecessarily complicated - it could be that your data should really be stored in an array in the first place, not as individual variables like you have done. That would save you several steps here. Hope that can start you in the right direction - there might be an even simpler solution, but I am no expert, but then I don't see anyone else helping out...
     
    markowe, Nov 27, 2009 IP
  8. xenon2010

    xenon2010 Peon

    Messages:
    237
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #8
    just add a flag or a note near the variable value..
    somthing like:

    $killhousetries1 = "0 this is v1";
    $killhousetries2 = "1 this is v2";
    $killhousetries3 = "0 this is v3";
    $killhousetries4 = "0 this is v4";
     
    xenon2010, Nov 27, 2009 IP