Zils Zils - 3 years ago 264
PHP Question

using array_sum() except last value

$payamount=$_POST["payamount"];


$payamount
is an array contains 5,10,15,20,60
how to exclude last value 60 and sum the rest? like 5+10+15+20

I'm using
array_sum($payamount)
but need to calculate without the last value, where
array_sum($payamount)
is to calculate all values.

Answer Source
array_sum($payamount) - end($payamount)

end — Set the internal pointer of an array to its last element

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download