Code: Select all
$biggest = max($setting, $current);
Code: Select all
$biggest = max($setting, $current);
Code: Select all
text comp(2, 3);
function comp($a, $b, $c="max") {
if ($c == "max") { return ($a >= $b) ? $a : $b; }
elseif ($c == "min") { return ($a <= $b) ? $a : $b; }
}
Code: Select all
function max($a, $b) { return ($a >= $b) ? $a : $b; }
function min($a, $b) { return ($a <= $b) ? $a : $b; }
Code: Select all
text max(-9, 99, , -999); // test 4 operands, with 3rd omitted
function max($a, $b, $c, $d, $e) {
$ret = -2147483648; // smallest 32bit: x'80000000'
if (($a != '') && ($a > $ret)) { $ret = $a; } // use if specified, *and* if bigger
if (($b != '') && ($b > $ret)) { $ret = $b; }
if (($c != '') && ($c > $ret)) { $ret = $c; }
if (($d != '') && ($d > $ret)) { $ret = $d; }
if (($e != '') && ($e > $ret)) { $ret = $e; }
Return $ret;
}
Code: Select all
text max("-9, 99, , -999"); // test 4 operands, with 3rd omitted
function max($a){foreach($num,$a,","){$ret=($num>$ret)?trim($num):$ret;}return $ret;}
Code: Select all
function max($a) {
foreach($num, $a, ",") {
$ret = ($num > $ret)? trim($num) : $ret;
}
return $ret;
}
Oh - double errorSammaySarkar wrote:@PeterH: a user function can have at most 11 arguments.
ed. also, any particular reason for the region-dependant $ret? Why not just "-2147483648" or hextodec('0x80000000') ?
btw, added both to UDF exchange.
Code: Select all
$ret = -2147483648; // smallest 32bit: x'80000000'
Sure!FluxTorpedoe wrote:for an often used, but only once coded function I think that some lines more for "common handling" are OK.