i have a simple question:
i have this var: $v = "24000,1500,1500,1500,1500,1500,";
i would like to add those numbers together.
i've tried to str_replace
the ,
with +
and so a eval()
, but that didn't worked.
i also tried str_split()
but it doesn't know to split on the ,
.
maybe if somehow convert it to an array and do a array_sum
...
any ideas?
thanks
$sum = array_sum( explode( ',', $v ) );
What this does is split $v
by the delimiter ,
with explode()
and sum the resulting array of parts with array_sum()
.
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