PHPize Online / SQLize Online  /  SQLtest Online

A A A
Share      Blog   Popular
Copy Format Clear
Copy Clear
Copy Format Clear
<?php function bigSum(string $a, string $b): string { $a_arr = array_reverse(str_split($a)); $b_arr = array_reverse(str_split($b)); $res = []; $l = max(count($a_arr), count($b_arr)); $next = 0; for ($c=0; $c<$l; $c++) { $r = ($a_arr[$c] ?? 0) + ($b_arr[$c] ?? 0) + $next; if ($r < 10) { $res[] = $r; $next = 0; else { $res[] = $r % 10; $next = 1; } } return implode('', array_reverse($res)); } echo bigSum('1000000000000000000000000000001','465');
Show:  
Copy Clear