how to find min value with out count zero in php?

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));



Take a look at array_diff() and func_get_args().

Try this

function nonzero($a){ 
   return ($a > 0); 


write you function :

function myMin()
$numargs = func_num_args();

$arg_list = func_get_args();
$min = PHP_INT_MAX ; 
for ($i = 0; $i < $numargs; $i++) {
    if($arg_list[$i] != 0 && $arg_list[$i] < $min)
          $min = Arg_list[$i];
return $min;

call : mymin(0,1,2,3,5) => 1

Need Your Help

How to prevent “Stop running this Script” in browsers?

javascript jquery

I have an ASP.NET MVC page that has JQuery Editable Datatable that has 14 columns.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.