I need to get the lowest among the values of 5 variables.
I want that if a variable is not set or it is empty, the script must exclude this variable from the results.
$var1='17';
$var2='19';
$var3='20';
$var4='1';
$var5='';
$arr = compact('var1','var2','var3','var4','var5'); // Stores values in array $arr
$highval = max($arr);
$lowval = min($arr);
$stores=count(array_filter($arr));
echo 'Item is available in '.$stores.' vars and is between '.$lowval.' and '.$highval.'';
For example assigning $var4=''
, the lowest value would be $var1
and not $var4
. There can also be multiple variables as not set or empty.
How would you edit the script above to accomplish it?