1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

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.
    SEMrush
    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
    SEMrush
  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