How would you best write a function to select min() in PHP, but ignoring empty values?
function minvar($var1,$var2) {
$min=min($var1,$var2);
return $min;
}
I know you could do it with if etc, but I thought there would be an more elegant way?
Note, that it will treat
0as “undefined” too.Update: When all values are empty
PHP_INT_MAXis returned. In this implementation it is intended, because the OP explictely ask to ignore empty values. Therefore when all values are ignored the minimum value is in fact the overall maximum (somehow). My main intention is to keep the return value strict: When the method says to ignore empty values it would be unexpected, that in some cases it still returnnullnonetheless.