y u no do it?

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.

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

Mar 21, 2006 IP
2. ### rvarcherPeon

Messages:
69
4
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:

Mar 21, 2006 IP

Messages:
1,844
153
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:

Mar 21, 2006 IP

Messages:
69