i want to find min value with out count zero form min() function in php, but it get me with zero, how can I find out with out zero?
$a = 0; $b = 3; $c= 4, $d = 8;
$minvalue = min($a,$b,$c,$d);
the expected result which I want is to be 3, but it gives me zero,
how can i neglect zero, i want a result with out zero, please help me to do this. thanks in advance
Something like this
function ownMin($value)
{
return min(array_filter(func_get_args()));
}
$a = 0; $b = 3; $c= 4; $d = 8;
echo ownMin($a,$b,$c,$d); // 3
Try this:
function my_min(){
$excludes = array(0); // anything, that should be filtered out.
$values = array_diff(func_get_args(), $excludes);
return min($values);
}
var_dump(my_min(12, 0, 15, 0, 18));
Shows:
int(12)
Take a look at array_diff()
and func_get_args()
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With