how to do a sum on a string in php?

前端 未结 5 1077
忘掉有多难
忘掉有多难 2021-01-18 14:58

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

5条回答
  •  不要未来只要你来
    2021-01-18 15:50

    $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().

提交回复
热议问题