Comparing values, finding largest one.

Discussion in 'PHP' started by Greg-J, Mar 21, 2006.

  1. #1
    I'm not sure of the best way to go about doing this.

    I have 4 values ($strings) and must set a fifth value to the highest numerical value of the 4 preceding. I'm not sure if I should put them in to an array and then find the highest number in that array, or if there is a simpler method.

    For reference the values are:
    $rtl
    $rtr
    $rbr
    $rbl

    and the largest number of those values will be set to $sz


    Thank you an advance for your help.
     
    Greg-J, Mar 21, 2006 IP
  2. rvarcher

    rvarcher Peon

    Messages:
    69
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #2
    I would do this:
    
    $sz = 0;
    if ( $rtl > $sz ) $sz = $rtl;
    if ( $rtr > $sz ) $sz = $rtr;
    if ( $rbr > $sz ) $sz = $rbr;
    if ( $rbl > $sz ) $sz = $rbl;
    
    PHP:
     
    rvarcher, Mar 21, 2006 IP
  3. Greg-J

    Greg-J I humbly return to you.

    Messages:
    1,844
    Likes Received:
    153
    Best Answers:
    0
    Trophy Points:
    135
    #3
    Thank you for your reply. I did end up finding a solution though.

    $sz = max($rtl, $rtr, $rbr, $rbl);
    PHP:
     
    Greg-J, Mar 21, 2006 IP
  4. rvarcher

    rvarcher Peon

    Messages:
    69
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #4
    That's cool. Learn something new everyday.
     
    rvarcher, Mar 21, 2006 IP