This is a simple question,I guess, but I couldn't figure it out.
How do I get a total sum of sequential numbers in PHP Like 2,4,6,8,10 . . . .1000
Thank you for the help.
$sum = array_sum(explode(',', '2,4,6,8'));
edit: if you just want the sum of even numbers within a range you could
$sum = array_sum(range(2,1000,2));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With