Answers for "sum of numbers with comma php"

PHP
1

sum of numbers with comma php

<?php
  $input = "1,2,3,4,5,6,7,8,9,10";
    
    $sum = 0;
    
    $input_arr = explode(",", $input);
    
    print_r(array_sum($input_arr)); #with array function
    
    // without array function
    
    $sum = 0;
    foreach($input_arr as $v){
    	//print "</br>".$v;
		$sum = $sum + $v;    
    }
    print "</br>".$sum;   
?>
Posted by: Guest on February-04-2021

Browse Popular Code Answers by Language