Forum Moderators: coopster
I started with this
if ($a_rows > $b_rows AND $a_rows >= $c_rows) { $max_rows = $a_rows; }
if ($b_rows > $a_rows AND $b_rows > $c_rows) { $max_rows = $b_rows; }
if ($c_rows > $a_rows AND $c_rows >= $b_rows) { $max_rows = $c_rows; }
Needless to say, $max_rows was NULL once $a_rows and $c_row were of equal value and $b_rows was less than both. So I modified my conditions, making them >=,
if ($a_rows >= $b_rows)
That helped. But I'm looking at this and wondering..
There must be a more efficient way to compare the 3 numbers and determine the value of $max_rows.
The other thing is as you go you could just compare whether they are larger than the one before, if they are equal then you can keep either as they are the same.
$max_rows = ($a_rows>$b_rows)?(($a_rows>$c_rows)?$a_rows: (($c_rows>$b_rows)?$c_rows:$b_rows))): (($b_rows>$c_rows)?$b_rows: (($c_rows>$a_rows)?$c_rows:$a_rows));
*gg*
[edited by: jatar_k at 10:33 pm (utc) on Feb. 20, 2005]
[edit reason] fixed sidescroll [/edit]
That expression didn't exactly work, it needs some fine tuning. I'll work on it. Ternary operators are not my strong suit, but I suspect that would be more efficient way to code for these comparisons.
As I say, I'll work on it, but it's academic at this point. Stuffing an array and obtaining my upper limit was a snap.
$max_rows = max($a_rows, $b_rows, $c_rows);
If there's a chance that one of the variables will be a string, make sure to read the manual for caveats or you may get unexpected results
$max = ("Whoops, this is a string", 0, 0, 0);
echo $max;
outputs "Whoops, this is a string"
I really did look for it...
Thanks!