Hi! Could we please enable some services and cookies to improve your experience and our website?

PHPize Online / SQLize Online  /  SQLtest Online

A A A
Login    Share code      Blog   FAQ

Online Sandbox for SQL and PHP: Write, Run, Test, and Share SQL Queries and PHP Code

Copy Format Clear

Stuck with a problem? Got Error? Ask AI support!

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; } } if ($next > 0) $res[] = $next; return implode('', array_reverse($res)); } echo bigSum('1000000000000000000000000000007','465');
Copy Clear