NOTE: I am sorry if this question has been asked. but the ones that have been asked and answered do not directly address the condition in my question. that is why i have asked it.
I have this code that sorts my list from lowest value to highest value and then it sums the first three But the variables keep changing
<?php $zero = 0; $one = 1; $two = 2; $three = 3; $four = 4; ?>
<?php
$arr = array($zero,$one,$two,$three,$four);
asort($arr); // sort ascending, lowest first
$tre = array_slice($arr, 0, 3); // first three
$sum = array_sum($tre); // summed up
?>
<div id="result"><?php echo $sum; ?></div>
What this code does, is that it sums up the first three numbers in ascending order including the zero i.e.
0+1+2 = 3
But that is not what i want, I would want it to sum up the first three numbers in ascending order but to ignore the zeros i.e. in my case
1+2+3 = 6
in addition: if a code can eliminate zero and also an empty value, it could be much better but not necessary
Any help on how i could go about this?