add comma to numbers php code example

Example 1: php number format

$num = 12345.6789;
echo number_format($num, 2, '.', '') //12345.67
echo number_format($num, 3, ',', '.') //12.345,678

Example 2: 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;   
?>

Tags:

Php Example