Search code examples
phpvariablesminzero

PHP MIN to exclude 0 value


I have 3 numeric values that I want to find the the lowest value. So I use min(), like this:

$last_activity = min($last_article, $last_comment, $last_video);

Is it possible to make min() exclude a variable if its value is 0? Note that the three variables are simple strings with a number like 10, not arrays...


Solution

  • No, min has no such option. But you have the option to filter any 0 values first:

    min(array_filter([$last_article, $last_comment, $last_video]))